PHP three-dimensional array deduplication (sample code)_PHP tutorial

WBOY
Release: 2016-07-13 10:25:10
Original
925 people have browsed it

Suppose the array is called $my_array;

Copy the code The code is as follows:

// Create a new empty array.
$tmp_array = array();

$new_array = array();

// 1. Loop out all the rows. ($val is a certain row)
foreach($my_array as $k => $val){

$hash = md5(json_encode($val));
if (in_array($hash, $tmp_array)) {
echo('This line already exists');
}else {
// 2. In the body of the foreach loop, assign the hash of each row of array object to the temporary array.
$tmp_array[] = $hash;
$new_array[] = $ val;
}
}

print_r($new_array);


$new_array is the filtered array without duplicate data.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825203.htmlTechArticleAssume the array is called $my_array; copy the code as follows: // Create a new empty array. $tmp_array = array( ); $new_array = array(); // 1. Loop out all the rows. ($val is a certain row)...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!