81446
![How to remove duplicate values in PHP? [duplicate]](https://www.xszz.org/skin/wt/rpic/t1.jpg)
Question:
This question already has an answer here:
<ul><li> <a href="/questions/307650/how-to-remove-duplicate-values-from-an-array-in-php" dir="ltr" rel="nofollow">How to remove duplicate values from an array in PHP</a> <span class="question-originals-answer-count"> 21 answers </span> </li> </ul>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.
Answer1:Asked before.
$array = array(1, 2, 2, 3);
$array = array_unique($array); // Array is now (1, 2, 3)
Answer2:Use the array_unique()
function, like this:
$noDuplicates = array_unique($categoryTotal);
<a href="http://php.net/manual/en/function.array-unique.php" rel="nofollow">Docs here</a>.