tags:

views:

58

answers:

3

Is there any way to have an array with items like:

$array[1];
$array[3];
$array[4];

Be turned into an array like this:

$array[1];
$array[2];
$array[3];

So that the array has only sequential numeric keys? Thanks!

-iMaster

A: 
$array = array_merge($array, array());

As long as $array has numerical keys, it will reorder them (starting from 0), numerically.

Chacha102
+7  A: 

array_values() returns all the values from the input array and indexes numerically the array.

therefromhere
+1  A: 

You can call array_values() on that array, and it will return a newly indexed array. (This assumes you have a numerically indexed array of course)

Dominic Barnes