在PHP反向阵列 [英] Reverse array in php
本文介绍了在PHP反向阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
array(7) {
[0]=> array(2) { ["id"]=> string(1) "9" ["roi"]=> float(0) }
[1]=> array(2) { ["id"]=> string(1) "1" ["roi"]=> float(0) }
[2]=> array(2) { ["id"]=> string(2) "10" ["roi"]=> float(0) }
[3]=> array(2) { ["id"]=> string(2) "14" ["roi"]=> float(0) }
[4]=> array(2) { ["id"]=> string(1) "4" ["roi"]=> float(0) }
[5]=> array(2) { ["id"]=> string(1) "5" ["roi"]=> float(141) }
[6]=> array(2) { ["id"]=> string(1) "6" ["roi"]=> float(2600) }
}
我只是想扭转这一点,所以ID 6(与2600 ROI)是第一位的数组等等英寸
I would just like to reverse this, so id 6 (with roi of 2600) comes first in the array etc.
我怎样才能做到这一点? array_reverse()
和 rsort()
在这种情况下不能正常工作
How can I do this? array_reverse()
and rsort()
does not work in this case
推荐答案
<一个href=\"http://php.net/manual/en/function.array-reverse.php\">http://php.net/manual/en/function.array-reverse.php:
$newArray = array_reverse($theArray, true);
最重要的部分是真正
参数,其中preserves键。
The important part is the true
parameter, which preserves the keys.
不相信?你可以看到它在行动上这个codePAD exampole 。
Not convinced? You can see it in action on this codepad exampole.
这篇关于在PHP反向阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文