Php-Arrays function-array_unique-Remove repeated values from the array

Source: Internet
Author: User
Array_unique () removes repeated values from the array [function] This function returns a new array with no repeated values based on the specified array, the key name remains unchanged. this function first sorts the values as strings, then retains only the first key name encountered for each value, and then ignores all subsequent key names... syntaxHighlighter. all ();

Array_unique () removes repeated values from the array

[Function]
This function returns a new array with no repeated values based on the specified array, and the key name remains unchanged.
This function first sorts values as strings, and then retains only the first key name for each value,
Then, ignore all the key names
This does not mean that the first key name that appears with the same value in the unordered array is retained.
Scope of use]
Php4> = 4.0.1, php5.
[Use]
Mixed array_unique (array)
Array/required/the original array to be processed by the function
[Example]
[Php]
$ Input = array ('C' => "green", 'AED', 'B' => 'green', 'Blue ', 'bed ');
Var_dump (array_unique ($ input ));
/*
Array (4 ){
["C"] =>
String (5) "green"
[0] =>
String (3) "aed"
[1] =>
String (4) "blue"
[2] =>
String (3) "bed"
}
*/

 


Taken from zuodefeng's note

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.