A simple example of php three-dimensional array deduplication

WBOY
Release: 2016-07-25 08:55:37
Original
1143 people have browsed it
  1. // Create a new empty array.

  2. $tmp_array = array();
  3. $new_array = array();
  4. // 1. Loop out all the rows. ($val is a certain row)
  5. foreach($my_array as $k => $val){
  6. $hash = md5(json_encode($val));
  7. if (in_array($hash, $tmp_array)) {
  8. echo('This row already exists');
  9. }else{ // bbs.it-home.org
  10. // 2. In the body of the foreach loop, assign the hash of each row of array objects to the temporary array中.
  11. $tmp_array[] = $hash;
  12. $new_array[] = $val;
  13. }
  14. }
  15. print_r($new_array);

  16. //$new_array is none after filtering Array of repeated data.

Copy code


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!