利用 array_unique()
範例:
<?php
$test = ['aaa','bbb','ccc','ddd','aaa'];
$test = array_unique($test);
print_r($test);
?>
輸出:
Array
(
[0] => aaa
[1] => bbb
[2] => ccc
[3] => ddd
)
官方文件:
http://php.net/manual/zh/function.array-unique.php
<?php
$test = ['aaa','bbb','ccc','ddd','aaa'];
$test = array_unique($test);
print_r($test);
?>
Array
(
[0] => aaa
[1] => bbb
[2] => ccc
[3] => ddd
)
http://php.net/manual/zh/function.array-unique.php