remove duplicates from array (array unic by key)

前端 未结 7 2239
一生所求
一生所求 2021-02-19 14:33
Array
(
    [0] => Array
        (
            [file] => /var/websites/example.com/assets/images/200px/1419050406e6648e1c766551a0ffc91380fd6ff3406002011-10-233750.         


        
7条回答
  •  清歌不尽
    2021-02-19 14:42

    As array_unique operates on flat arrays, you can not use it directly. But you can first map all 'md5' values to a flat array, unique it and then get the elements with array_intersect_key:

    $allMd5s = array_map(function($v) {return $v['md5'];}, $array);
    
    $uniqueMd5s = array_unique($md5);
    
    $result = array_intersect_key($arr, $uniqueMd5s);
    

提交回复
热议问题