php 3D array to duplicate the of sample code

  • 2020-11-25 07:11:35
  • OfStack

Let's say I call the array $my_array;


//  new 1 An empty array .
$tmp_array = array();
$new_array = array();
// 1.  Loop out all the rows . ( $val  That's some row )
foreach($my_array as $k => $val){
    $hash = md5(json_encode($val));
    if (in_array($hash, $tmp_array)) {
        echo(' We've already done this row ');
    }else{
        // 2.  in  foreach  In the body of the loop ,  Each row of the array object to get hash  Are assigned to that temporary array .
        $tmp_array[] = $hash;
        $new_array[] = $val;
    }
}
print_r($new_array);

$new_array is the filtered array with no duplicate data.


Related articles: