Page 1 of 1

Rearranging arrays

Posted: Fri Apr 07, 2006 5:05 am
by someberry
Is it possible to change a higher level index without changing any of its sub levels? Such as this:

Code: Select all

Starting with
-------------

Array
(
    [0] => array_name_1
        (
            [0] => some value 1
            [1] => some value 2
        )

    [1] => array_name_2
        (
            [0] => some value 3
            [1] => some value 4
        )
}

Ending with
-----------

Array
(
    [0] => NEW_array_name_1
        (
            [0] => some value 1
            [1] => some value 2
        )

    [1] => NEW_array_name_2
        (
            [0] => some value 3
            [1] => some value 4
        )
}
There is probably a function for this, but searching through the PHP manual on arrays I couldn't find anything :(

Thanks,
someberry

Posted: Fri Apr 07, 2006 7:29 am
by feyd
Because of how named index arrays work, it's not possible in a single, built-in function call, however with numericly index arrays array_splice() works.