Home > Backend Development > PHP Tutorial > 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
Release: 2023-02-28 20:46:02
Original
2542 people have browsed it


<?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"
}
Copy after login





source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template