PHP删除Array数组里指定的key
<?php
function array_remove_by_key($data, $key){
if(!array_key_exists($key, $data)){
return $data;
}
$keys = array_keys($data);
$index = array_search($key, $keys);
if($index !== FALSE){
array_splice($data, $index, 1);
}
return $data;
}
$data = array('name'=>'zhangsan','age'=>12,'address'=>'china');
$result = array_remove_by_key($data, 'age');
var_dump($result);