PHP Array function sequence Array_unique ()-Removes duplicate element values from the array

Source: Internet
Author: User
Array_unique () Definition and usage
The Array_unique () function shifts the duplicate values in the array and returns the result arrays.

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

The key name in the returned array is not changed.

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

Description
Array_unique () Sorts the values first as a string, then retains only the first key name encountered for each value, and then ignores all subsequent key names. This does not mean that the key name of the first occurrence of the same value in an unordered array is preserved.

Hints and Notes
Note: The returned array will hold the key type of the first array element.

Example

<?php $a =array ("a" and "cat", "b" = "Dog", "C" and "cat"); Print_r (Array_unique ($a));?>

Output:

Array ([A] = Cat [b] = Dog)

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.