php二维数组去除重合数据

WBOY
Release: 2016-06-23 14:14:46
Original
1163 people have browsed it

PHP 二维数组

Array
(
    [0] => Array
        (
            [knowledge_id] => 1
            [tag_id] => 2
        )

    [1] => Array
        (
            [knowledge_id] => 1
            [tag_id] => 3
        )

)

把他里面量相同的[knowledge_id] => 1合并只留一个??????

回复讨论(解决方案)

留哪个呢?还是2个 tag_id 都要?

不用只要一个数组[0] => Array
        (
            [knowledge_id] => 1
            [tag_id] => 2
        )

设原数组为 $ar, 则

$res = array(); //结果数组foreach($ar as $v) {  if(! isset($res[$v['knowledge_id']])) $res[$v['knowledge_id']] = $v;}$res = array_values($res);
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!