array_unique() 没有正常运行?
array_unique() not functioning as it should?
我在变量 $votes
中有一个数组。 print_r($votes)
给我们:
Array ( [0] => 1 [1] => 1 [2] => 1 )
所以我们有三个值,都设置为1
。
现在,我想让数组只有唯一值,这意味着如果有三个值匹配 1
,则删除其中两个。
为此,我尝试了 array_unique($votes);
但它没有删除任何值。为什么?!
您必须像这样再次将 array_unique
的输出分配给数组:
$votes = array_unique($votes);
作为参考,您可以查看手册:http://php.net/manual/en/function.array-unique.php
引自那里:
Takes an input array and returns a new array without duplicate values.
我在变量 $votes
中有一个数组。 print_r($votes)
给我们:
Array ( [0] => 1 [1] => 1 [2] => 1 )
所以我们有三个值,都设置为1
。
现在,我想让数组只有唯一值,这意味着如果有三个值匹配 1
,则删除其中两个。
为此,我尝试了 array_unique($votes);
但它没有删除任何值。为什么?!
您必须像这样再次将 array_unique
的输出分配给数组:
$votes = array_unique($votes);
作为参考,您可以查看手册:http://php.net/manual/en/function.array-unique.php
引自那里:
Takes an input array and returns a new array without duplicate values.