Rearranging arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someberry
Forum Contributor
Posts: 172
Joined: Mon Apr 11, 2005 5:16 am

Rearranging arrays

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply