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.
http://www.bkjia.com/PHPjc/825203.htmlwww.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)...
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