Php array_unique Delete repeated array values

Source: Internet
Author: User

Php array_unique is actually very useful. I often see repeated content in regular expressions, but I like to delete repeated array values with array_unique.

Php array_unique is actually very useful. I often see repeated content in regular expressions, but I like to delete repeated array values with array_unique.

Array_unique
("= 4.0.1, PHP 5" in PHP 4)

Array_unique-delete an array of repeated values

Description
Array array_unique (array $ array [Abstract $ sort_flags = SORT_REGULAR])
Take an input array and return a new array with no repeated values.

Note that the key is saved. Various values of array_unique () are treated as strings, and then each value of the first key that is continuously encountered ignores all the keys below. This does not mean that the key first batch of unordered values will be maintained.

Note: two factors are considered equal when and only when (string) $ elem1 ===( string) $ elem2. VERBAL: When the strings are the same. The first item will be used.

Parameters

Array
Input array.

Sort_flags
The optional second parameter sort_flags can be used to modify the sorting behavior and use these values:

Sorting type ID:

SORT_REGULAR-general comparison (without changing the type)
SORT_NUMERIC-numerical comparison
SORT_STRING-string comparison
SORT_LOCALE_STRING-compares strings based on the current region. The time is in PHP 4.4.0 and 5.0.2. In PHP 6, the locale of the system it uses can be changed to setlocale (). From PHP 6, you must use the i18n_loc_set_default () function.


Return Value
Returns the filter array.

Modify

Version description
Optional sort_flags at 5.2.9.


Instance

Example #1 array_unique ()

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.