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

零下一度
Release: 2023-03-10 19:18:01
Original
1815 people have browsed it

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 即为筛选后无重复数据的数组。
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template