开发中经常遇到各种数组操作问题,PHP自带的方法可能已经不能满足日常需求,我们就需要去考虑利用PHP的方法写出更多的方法。
//$arr->传入数组 $key->判断的key值
function array_unset_tt($arr,$key){
//建立一个目标数组
$res = array();
foreach ($arr as $value) {
//查看有没有重复项
if(isset($res[$value[$key]])){
//有:销毁
unset($value[$key]);
}
else{
$res[$value[$key]] = $value;
}
}
return $res;
}演示:
$arr = array(
array(
'title'=>'1111','date'=>'ddddd'
),
array('title'=>'22222','date'=>'fffffff'),
array('title'=>'1111','date'=>'ggggggg')
);
$newArr = array_unset_tt($arr,'title');
echo '
';
print_r(array_values($newArr));