Morning all,

I have the following array:
Array
(
[0] => 1
[1] => 2
[2] => 3
[6] => 27
[7] => 28
[8] => 29
[9] => 30
[10] => 21
)

is there a simple function that will reindex the array to be a normal incrementally indexed array ie.

Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 27
[4] => 28
[5] => 29
[6] => 30
[7] => 31
)

Cheers all.
HS

    Howdy,

    Thanks for the tip unfortunately it doesn't do exactly what I wanted. It returns the arrays index in an ordered array.

    Instead I've written the following function:

    function reIndexArray($array) {
        $count = "0";
        $new_array = array();
        foreach ($array as $key=>$item) {
            array_push($new_array, $item);
        }
    
        return $new_array;
    }

    which does the trick.

    I was hoping for a more elegant solution.

    Cheers,
    HS

      It returns the arrays index in an ordered array.

      Have you actually tried using it?

      $array = array_values($array);

        Originally posted by laserlight
        Have you actually tried using it?

        $array = array_values($array);

        ooops my bad.

        array_keys was used 🙁

        Thanks

          Write a Reply...