PHP需要递归扭转数组 [英] PHP Need to recursively reverse an array
本文介绍了PHP需要递归扭转数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要递归扭转了子阵列的多层次的一个巨大的数组,我需要preserve所有的键(其中有些是INT键,还有一些是字符串键),有人可以帮我?也许一个例子使用array_reverse不知何故?此外,使用array_reverse这样做的唯一/最好的方法是什么?
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 someone please help me? Perhaps an example using array_reverse somehow? Also, is using array_reverse the only/best method of doing 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);
}
这篇关于PHP需要递归扭转数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文