this give results like
这给出了结果
Array( [0] => 5000 [1] => 5001 [2] => 3000 [3] => 3001 [4] => 5000 )
数组([0] => 5000 [1] => 5001 [2] => 3000 [3] => 3001 [4] => 5000)
When I use array_unique same result is obtained
当我使用array_unique时,获得了相同的结果
Array ( [0] => 5000 [1] => 5001 [2] => 3000 [3] => 3001 [4] => 5000 )
数组([0] => 5000 [1] => 5001 [2] => 3000 [3] => 3001 [4] => 5000)
foreach($detail as $key => $value){
array_push($zips, $value);
}
}
array_unique($zips);
2 个解决方案
#1
6
array_unique()
does not work by reference. That means, it won't actually modify the original array, just return a new array with the respective modifications. You need to save its output to a new (or the same) variable:
array_unique()不能通过引用工作。这意味着,它实际上不会修改原始数组,只返回一个具有相应修改的新数组。您需要将其输出保存为新的(或相同的)变量:
foreach($detail as $key => $value){
array_push($zips, $value);
}
$zips = array_unique($zips);
Read more about Passing by Reference
阅读更多关于Passing by Reference的信息
#2
1
No need foreach
and array_push
, just apply and save to the needed variable $zips
:
不需要foreach和array_push,只需应用并保存到所需的变量$ zips:
$zips = array_unique(array_values($zips));
#1
6
array_unique()
does not work by reference. That means, it won't actually modify the original array, just return a new array with the respective modifications. You need to save its output to a new (or the same) variable:
array_unique()不能通过引用工作。这意味着,它实际上不会修改原始数组,只返回一个具有相应修改的新数组。您需要将其输出保存为新的(或相同的)变量:
foreach($detail as $key => $value){
array_push($zips, $value);
}
$zips = array_unique($zips);
Read more about Passing by Reference
阅读更多关于Passing by Reference的信息
#2
1
No need foreach
and array_push
, just apply and save to the needed variable $zips
:
不需要foreach和array_push,只需应用并保存到所需的变量$ zips:
$zips = array_unique(array_values($zips));