Home  >  Article  >  Backend Development  >  PHP uses array_unique to determine whether the same value exists in the array

PHP uses array_unique to determine whether the same value exists in the array

ringa_lee
ringa_leeOriginal
2018-05-10 15:45:482521browse


<?php
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);
print_r($result);
?>
复制代码
输出结果:
Array
(
[a] => green
[0] => red
[1] => blue
)
例2. array_unique() 和类型
<?php
$input = array(4, "4", "3", 4, 3, "3");
$result = array_unique($input);
var_dump($result);
?>
复制代码
输出结果:
array(2) {
[0] => int(4)
[2] => string(1) "3"
}





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