Home  >  Article  >  Backend Development  >  A simple example of php three-dimensional array deduplication

A simple example of php three-dimensional array deduplication

WBOY
WBOYOriginal
2016-07-25 08:55:371143browse
  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


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