phparraysarray-unique

PHP arrays: delete duplicates and reorder keys


I have this array:

$gspa['aryNumEmp']
: array = 
  0: string = 41
  1: string = 41
  2: string = 41
  3: string = 41
  4: string = 41
  5: string = 41
  6: string = 41
  7: string = 41
  8: string = 41
  9: string = 2355
  10: string = 2355
  11: string = 2355
  12: string = 2355
  13: string = 2355
  14: string = 2355

I want this array without duplicates so I do:

array_unique($gspa['aryNumEmp'])

And now I have:

: array = 
  0: string = 41
  9: string = 2355

What do I have to do to get the array keys reordered like that:

: array = 
  0: string = 41
  1: string = 2355

Thanks!!


Solution

  • Use array_values() to re-key the array.

    $new_array = array_values(array_unique($gspa['aryNumEmp']));