Home  >  Article  >  Backend Development  >  PHP two-dimensional array deduplication based on a certain element

PHP two-dimensional array deduplication based on a certain element

不言
不言Original
2018-04-28 13:59:393790browse

This article mainly introduces the PHP two-dimensional array deduplication according to a certain element, which has a certain reference value. Now I share it with you. Friends in need can refer to it

 function array_unset($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 &#39;<pre class="brush:php;toolbar:false">&#39;;  
  
print_r(array_values($newArr));

Related recommendations:

PHP two-dimensional array sorting by key value

php two-dimensional array deduplication method

The above is the detailed content of PHP two-dimensional array deduplication based on a certain element. For more information, please follow other related articles on the PHP Chinese website!

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