PHP array deduplication/

Source: Internet
Author: User
PHP array deduplication? Array deduplication
$ Term = array_column ($ grade, 'condition'); $ term = array_flip ($ term); print_r ($ term );

Effect:


Principle:

Array_flip ():

The function returns an inverted array. if the same value appears multiple times, the last key name will be used as its value, and all other key names will be lost.

If the data type of the value in the original array is not a string or integer, the function reports an error.


Two key-value exchanges. because PHP does not allow duplicate key names, deduplication is achieved.


Method 2:

Print_r (array_unique ($ term ));

The array_unique () function removes repeated values from the array and returns the result array.

When the values of several array elements are equal, only the first element is retained, and other elements are deleted.

The input key of the returned array remains unchanged.

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.