Home > Backend Development > PHP Tutorial > 算法 - php数组过滤问题

算法 - php数组过滤问题

WBOY
Release: 2016-06-06 20:33:03
Original
998 people have browsed it

tagId不同,但是tagName和tagType相同即算相同的,遇到怎么把后面的那个删除掉。

<code>[17] => Array
    (
        [tagId] => 9677
        [tagName] => 羚羊感冒片
        [tagType] => 2
    )

[18] => Array
    (
        [tagId] => 9678
        [tagName] => 羚羊感冒片
        [tagType] => 2
    )
</code>
Copy after login
Copy after login

回复内容:

tagId不同,但是tagName和tagType相同即算相同的,遇到怎么把后面的那个删除掉。

<code>[17] => Array
    (
        [tagId] => 9677
        [tagName] => 羚羊感冒片
        [tagType] => 2
    )

[18] => Array
    (
        [tagId] => 9678
        [tagName] => 羚羊感冒片
        [tagType] => 2
    )
</code>
Copy after login
Copy after login

<code>php</code><code>$tags = array(
    Array(
            'tagId' => 9677,
            'tagName' => '羚羊感冒片',
            'tagType' => 2,
        )
    , Array
        (
            'tagId' => 9678,
            'tagName' => '羚羊感冒片',
            'tagType' => 2
        )
   );
  assoc_unique($tags,'tagName','tagType');
  print_r($tags);
function assoc_unique(&$arr, $key,$key2) { 
        $res=array();
        for($i=0;$i<count empty if></count></code>
Copy after login

把tagName和tagType联合起来,当做一个新数组的key不就得了

楼上说的方法最简单啦!把tagName和tagType链接起来作为新数组的key,自动过滤掉了重复值

Related labels:
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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template