Example of deduplication of php Arrays

Source: Internet
Author: User

Example of deduplication of php Arrays

This article mainly introduces the example of de-duplicated data in php arrays. Sometimes the obtained php arrays always contain duplicate values. You can use the following method to remove duplicate data.

Repeated data starting with a number is as follows:

 

The Code is as follows:

Array (

[0] = & gt; 100

[K1] = & gt; 100

[1] => 2123.

[K2] = & gt; 2123)

 

This method can remove the value of the number as the key, first sort the array in descending order of the key, and then remove the repeated values using the array_unique method.

It cannot be used in the following scenarios: different key values have the same value.

 

The Code is as follows:

Function array_unique_value ($ arr = array ()){

Array_multisort ($ arr, SORT_DESC, array_keys ($ arr ));

Print_r (array_unique ($ arr ));

}

 

 

Related Article

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.