0

this give results like

Array( [0] => 5000 [1] => 5001 [2] => 3000 [3] => 3001 [4] => 5000 )

When I use array_unique same result is obtained

Array ( [0] => 5000 [1] => 5001 [2] => 3000 [3] => 3001 [4] => 5000 )

foreach($detail as $key => $value){
            array_push($zips, $value);  
            }   
}

array_unique($zips);
halfer
  • 19,824
  • 17
  • 99
  • 186
Himani
  • 245
  • 1
  • 2
  • 20

2 Answers2

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:

foreach($detail as $key => $value){
    array_push($zips, $value);  
}   

$zips = array_unique($zips);

Read more about Passing by Reference

ishegg
  • 9,685
  • 3
  • 16
  • 31
  • No problem man. Read @RomanPerekhrest 's answer too in how to make it a bit more concise. Good luck! – ishegg Sep 12 '17 at 12:32
1

No need foreach and array_push, just apply and save to the needed variable $zips:

$zips = array_unique(array_values($zips));
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105