无涯教程-PHP - array_unique()函数

63 阅读1分钟

array_unique() - 语法

array_unique ( $array );

函数的作用是:从数组中删除重复的值。如果两个或多个数组值相同,则第一个外观将保持不变,而另一个将被删除。

Sr.No Parameter & Description
1

array1(必需)

它指定一个数组。

array_unique() - 示例

<?php
   $input=array("a" => "green", "red", "b" => "green", "blue", "red");
   $result=array_unique($input);

print_r($result); ?>

这将产生以下输出-

Array ( [a] => green [0] => red [1] => blue )
        <h2 id="h22">参考链接</h2><p><a target="_blank" href="https://www.learnfk.com/php/php-function-array-unique.html" style="">https://www.learnfk.com/php/php-function-array-unique.html</a></p>