remove duplicates from array (array unic by key)

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


        
7条回答
  •  -上瘾入骨i
    2021-02-19 14:34

     'alpha',
        'some' => 'value',
      ),
      array(
        'md5' => 'alpha',
        'some' => 'other value',
      ),
      array(
        'md5' => 'bravo',
        'some' => 'third value',
      ),
    );
    // walk input array
    $_data = array();
    foreach ($data as $v) {
      if (isset($_data[$v['md5']])) {
        // found duplicate
        continue;
      }
      // remember unique item
      $_data[$v['md5']] = $v;
    }
    // if you need a zero-based array, otheriwse work with $_data
    $data = array_values($_data);
    

提交回复
热议问题