Home >Backend Development >PHP Tutorial >Share the example code of using php three-dimensional array to remove duplicates

Share the example code of using php three-dimensional array to remove duplicates

零下一度
零下一度Original
2017-06-19 10:35:181820browse

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(&#39;这个行已经有过了&#39;);    }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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn