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

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

WBOY
Release: 2016-07-25 09:02:47
Original
1120 people have browsed it
  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


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