make array reserve without changing array keys

时间:2018-02-03 11:03:56

标签: php

Array
(
    [28] => Array
        (
            [menuitem_id] => 28
            [qty] => 1
        )

    [26] => Array
        (
            [menuitem_id] => 26
            [qty] => 1
        )

    [25] => Array
        (
            [menuitem_id] => 25
            [qty] => 1
        )

    [20] => Array
        (
            [menuitem_id] => 20
            [sub_item] => Array
                (
                    [3] => Array
                        (
                            [item_id] => 3
                            [qty] => 1
                        )

                )

        )

)

I have this array out put now i need to reverse the array but without changing its keys. i like to start the foreach loop from last array to first. thanks

1 个答案:

答案 0 :(得分:4)

array array_reverse ( array $array [, bool $preserve_keys = FALSE ] )

preserve_keys If set to TRUE numeric keys are preserved. Non-numeric keys are not affected by this setting and will always be preserved.

e.g.

array_reverse($input, true);

See PHP documentation