Two-dimensional arrays remove duplicate values and Array_unique functions

Source: Internet
Author: User

Today, the problem is that the array removed from the database is a two-dimensional array, now is the two-bit array to go to the weight, but in PHP, for a one-dimensional array, we can directly use the PHP system function Array_unique, but this function does not remove the multidimensional array to duplicate , so I need to write myself a function to remove the duplicate values of the two-dimensional array.

1 functionARRAY_UNIQUE_FB ($array 2D){ 2 3     foreach($array 2D  as $v){4         $v=Join(‘,‘,$v);//dimension, you can also convert one-dimensional array to a comma-concatenated string using implode5 6         $temp[]=$v;7 8     }9 Ten     $temp=Array_unique($temp);//Remove duplicate strings, that is, duplicate one-dimensional arrays One  A     foreach($temp  as $k=$v){ -  -        $temp[$k]=Explode(‘,‘,$v);//re-assemble the disassembled array the  -     } -  -     return $temp;

Two-dimensional arrays remove duplicate values and Array_unique functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.