问题
I need help. Want to remove duplicate values from array in php.
$categoryTotal echoes 144 125 262 108 351 177 266 269 270 268 309 144 125 262 238 108
On using:
vardump()
I get
Array ( [0] => 144 [1] => 125 [2] => 262 [3] => 108 [4] => 351 [5] => 177 [6] => 266 [7] => 269 [8] => 270 [9] => 268 [10] => 309 [14] => 238 )
I used sort to sort the values in ascending order I get:
108 108 125 125 144 144 177 238 262 262 266 268 269 270 309 351
but then using $categoryTotal=array_unique($categoryTotal,SORT_NUMERIC);
few values like 309 351
disappear.
Would like to know how to know out duplicate values from this array.
回答1:
Asked before.
$array = array(1, 2, 2, 3);
$array = array_unique($array); // Array is now (1, 2, 3)
回答2:
Use the array_unique()
function, like this:
$noDuplicates = array_unique($categoryTotal);
Docs here.
来源:https://stackoverflow.com/questions/16063590/how-to-remove-duplicate-values-in-php