1

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!!

0

2 Answers 2

3

Use array_values() to re-key the array.

$new_array = array_values(array_unique($gspa['aryNumEmp']));
Sign up to request clarification or add additional context in comments.

Comments

0

array_unique has been benchmarked as slow but that was prior to PHP7

That said, it's probably more performant to do array_keys(array_flip($originalArray))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.