php reverse array order code example

Example 1: php reverse array

$array= array(1,2,3,4,5);
$reversedArray = array_reverse($array);

var_dump($y);

Example 2: reverse order np array

reversed_arr = arr[::-1]

Example 3: array reverse php

array_reverse($array);

Example 4: php array_reverse keep keys

<?php
$input  = array("php", 4.0, array("green", "red"));
$reversed = array_reverse($input);
$preserved = array_reverse($input, true);

print_r($input);
print_r($reversed);
print_r($preserved);
?>

Example 5: php sort reverse

<?php
$fruits = array("lemon", "orange", "banana", "apple");
rsort($fruits);
foreach ($fruits as $key => $val) {
    echo "$key = $val\n";
}
?>