Home  >  Article  >  Backend Development  >  Uniqueid php determines whether the same value exists in the array array_unique

Uniqueid php determines whether the same value exists in the array array_unique

WBOY
WBOYOriginal
2016-07-29 08:37:341438browse

array_unique(PHP 4 >= 4.0.1, PHP 5)
array_unique -- Remove duplicate values ​​from the array
Description
array array_unique (array array)
array_unique() accepts array as input and returns a new array without duplicate values .
Note that the key name remains unchanged. array_unique() first sorts the values ​​as strings, then retains only the first encountered key for each value, and then ignores all subsequent keys. This does not mean that the first occurrence of the same value in an unsorted array will be preserved.
Note: Two units are considered the same if and only if (string) $elem1 === (string) $elem2. That is, when the expressions of the strings are the same.
The first unit will be retained.
Example 1. array_unique() example

Copy the code 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:

Copy code The code is as follows:


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


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

Copy the code The code is as follows:


$input = array(4, "4", "3", 4, 3, "3");
$result = array_unique($input);
var_dump($result);
?> [0] => int(4)
[2] => string(1) "3"

}

The above introduces how to determine whether the same value array_unique exists in an array under uniqueid PHP, including the content of uniqueid. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn