Home  >  Article  >  Backend Development  >  Enhanced version of array_unique function (supports two-dimensional arrays)

Enhanced version of array_unique function (supports two-dimensional arrays)

WBOY
WBOYOriginal
2016-07-25 09:02:471088browse
  1. //Remove duplicate values ​​from the two-dimensional array

  2. function array_unique_fb($array2D){
  3. foreach ($array2D as $v){
  4. $v = join("," ,$v); //For dimensionality reduction, you can also use implode to convert a one-dimensional array into a string connected with commas
  5. $temp[] = $v;
  6. }

  7. $temp = array_unique($temp); //Remove repeated strings, that is, repeated one-dimensional arrays

  8. foreach ($temp as $k => $v){
  9. $temp[$k] = explode("," ,$v); //Reassemble the disassembled array
  10. }
  11. return $temp;
  12. }?>

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