PHP two-dimensional array deduplication based on a certain element

不言
Release: 2023-03-25 06:52:02
Original
3766 people have browsed it

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));
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!