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

算法 - php数组过滤问题

WBOY
WBOYOriginal
2016-06-06 20:33:03987browse

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

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

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

回复内容:

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

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

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

<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>

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

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

Statement:
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