Reverse array in php

arrays, php

Solution

http://php.net/manual/en/function.array-reverse.php:

$newArray = array_reverse($theArray, true);

The important part is the `true` parameter, which preserves the keys.

Not convinced? You can see it in action on this codepad exampole.

Problem

``` 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) } } ``` I would just like to reverse this, so id 6 (with roi of 2600) comes first in the array etc. How can I do this? `array_reverse()` and `rsort()` does not work in this case

Original source