[php] array_unique移除陣列中重複的值
官方範例 1
<?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
<?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"
}
其它範例:
例子
<?php
$a=array("a"=>"Cat","b"=>"Dog","c"=>"Cat");
print_r(array_unique($a));
?>
輸出:
Array ( [a] => Cat [b] => Dog )