Php to determine whether the same value of array_unique_PHP exists in the array tutorial

Source: Internet
Author: User
Php checks whether the same value array_unique exists in the array. Array_unique (PHP44.0.1, PHP5) array_unique -- Remove repeated values from the array. This means that arrayarray_unique (arrayarray) array_unique () accepts array as input and returns a new array without repeated values. Array_unique (PHP 4> = 4.0.1, PHP 5)
Array_unique -- Remove repeated values from the array
Description
Array array_unique (array)
Array_unique () accepts array as input and returns a new array without repeated values.
Note that the key name remains unchanged. 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.
Note: when and only when (string) $ elem1 = (string) $ elem2, the two units are considered the same. That is, when the expression of a string is the same.
The first unit will be retained.
Example 1. array_unique () example

The code is as follows:


$ Input = array ("a" => "green", "red", "B" => "green", "blue", "red ");
$ Result = array_unique ($ input );
Print_r ($ result );
?>



The above example will output:

The code is as follows:


Array
(
[A] => green
[0] => red
[1] => blue
)



Example 2. array_unique () and type
The above example will output:

The code is as follows:


$ Input = array (4, "4", "3", 4, 3, "3 ");
$ Result = array_unique ($ input );
Var_dump ($ result );
?>



The code is as follows:


Array (2 ){
[0] => int (4)
[2] => string (1) "3"
}

Http://www.bkjia.com/PHPjc/318643.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/318643.htmlTechArticlearray_unique (PHP4 = 4.0.1, PHP5) array_unique -- Remove repeated values in the array description arrayarray_unique (arrayarray) array_unique () accepts array as input and returns a new array without repeated values ....

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.