Search code examples
phparraysarray-key

How do I reassign array positions in php?


Possible Duplicate:
How to re-index the values of an array in PHP?

I'm using several php functions to carry certain data over through an array, and through the process I get arrays that print_r like the following:

Array ([0] => 35 [4] => 36 [6] => 34)

What do I have to do if I want to reorder it back to the following? (I use a for statement and need the keys to be in consecutive order starting from 0 again)

Array ([0] => 35 [1] => 36 [2] => 34)

Solution

  • $array = array_values($array);