remove duplicates from array (array unic by key)

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


        
7条回答
  •  时光取名叫无心
    2021-02-19 14:48

    // your array
    $array = array(...);
    // will be used to store md5 hashes
    $md5 = array();
    // walk through array
    foreach ($array as $key => $arr) {
      // have we already seen this md5 hash?
      if (in_array($arr['md5'], $md5)){
        // remove element
        unset($array[$key]);
      }else {
        // keep element, but add it's md5
        $md5[] = $arr['md5'];
      }
    }
    

提交回复
热议问题