Php array function sequence-Remove repeated element values in the array-PHP Tutorial

Source: Internet
Author: User
Array_unique () of the php array function sequence-removes repeated element values from the array. Array_unique () defines and uses the array_unique () function to remove duplicate values from the array and return the result array. When the values of several array elements are equal, only the first element is retained. Array_unique () definition and usage
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.

Syntax
Array_unique (array)
Parameter description
Array is required. Specifies the input array.

Description
Array_unique () first sorts the values as strings, then retains only the first key name that is encountered for each value, and then ignores all the key names that follow. This does not mean that the first key name that appears for the same value in the unordered array will be retained.

Tips and comments
Note: The Returned array retains the key type of the first array element.

Example

The code is as follows:


$ A = array ("a" => "Cat", "B" => "Dog", "c" => "Cat ");
Print_r (array_unique ($ ));
?>


Output:

Array ([a] => Cat [B] => Dog)

The http://www.bkjia.com/PHPjc/324488.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324488.htmlTechArticlearray_unique () defines and uses the array_unique () function to remove duplicate values from the array and return the result array. When the values of several array elements are equal, only the first element is retained...

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.