0

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.

A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485

2 Answers2

3

Asked before.

$array = array(1, 2, 2, 3);
$array = array_unique($array); // Array is now (1, 2, 3)
karmafunk
  • 1,453
  • 12
  • 20
1

Use the array_unique() function, like this:

$noDuplicates = array_unique($categoryTotal);

Docs here.

Matt Cain
  • 5,638
  • 3
  • 36
  • 45