remove duplicates from array (array unic by key)

前端 未结 7 2240
一生所求
一生所求 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

    Use array_filter(). Quick code test (doesn't necessarily mirror your situation, but you should get the idea):

     array('name' => 'samson'),
        1 => array('name' => 'delilah'),
        2 => array('name' => 'samson'),
        3 => array('name' => 'goliath'),
    );
    
    $md5Processed = array();
    
    $newArray = array_filter($array, "uniqueMD5");
    
    print_r($newArray);
    
    exit;
    
    function uniqueMD5( $data ){
        global $md5Processed;
    
        if( !in_array( $data['name'], $md5Processed ) )
        {
            $md5Processed[] = $data['name'];
            return true;
        }
    }
    

提交回复
热议问题