Home >Backend Development >PHP Tutorial >Share the example code of using php three-dimensional array to remove duplicates
php three-dimensionalarrayremoval
This article introduces the method of deduplicating php three-dimensional array and shares a simple example.
If there is an array $my_array;
Example:
<?php// 新建一个空的数组.$tmp_array = array();$new_array = array(); // 1. 循环出所有的行. ( $val 就是某个行)foreach($my_array as $k => $val) { $hash = md5(json_encode($val)); if (in_array($hash, $tmp_array)) { echo('这个行已经有过了'); }else{ // www.jbxue.com // 2. 在 foreach 循环的主体中, 把每行数组对象得hash 都赋值到那个临时数组中. $tmp_array[] = $hash; $new_array[] = $val; } } print_r($new_array); //$new_array 即为筛选后无重复数据的数组。
The above is the detailed content of Share the example code of using php three-dimensional array to remove duplicates. For more information, please follow other related articles on the PHP Chinese website!