PHP Need to recursively reverse an array

后端 未结 3 583
遇见更好的自我
遇见更好的自我 2021-01-21 12:57

I need to recursively reverse a HUGE array that has many levels of sub arrays, and I need to preserve all of the keys (which some are int keys, and some are string keys), can so

3条回答
  •  无人及你
    2021-01-21 13:42

    Try this:

    function array_reverse_recursive($arr) {
        foreach ($arr as $key => $val) {
            if (is_array($val))
                $arr[$key] = array_reverse_recursive($val);
        }
        return array_reverse($arr);
    }
    

提交回复
热议问题