php二维数组除去重合数据
时间:2021-07-01 10:21:17
帮助过:6人阅读
php二维数组去除重合数据
Array
(
[0] => Array
(
[knowledge_id] => 1
[tag_id] => 2
)
[1] => Array
(
[knowledge_id] => 1
[tag_id] => 3
)
)
把他里面量相同的[knowledge_id] => 1合并只留一个??????
PHP
二维数组
分享到:
------解决方案--------------------设原数组为 $ar, 则
$res = array(); //结果数组
foreach($ar as $v) {
if(! isset($res[$v['knowledge_id']])) $res[$v['knowledge_id']] = $v;
}
$res = array_values($res);