PHP array_reverse function

Last Updated: February 15, 2022

array_reverse — Return an array with elements in reverse order

Syntax

 array_reverse(array $array, bool $preserve_keys = false): array

Supports (PHP 4, PHP 5, PHP 7, PHP 8)

Parameters

Parameter Description
array Required. target array
preserve_keys Optional : If set to true numeric keys are preserved. Non-numeric keys are not affected by this setting and will always be preserved. 

Return Value

returns the reversed array

Example

<?php
$arr1 = array("one","two","three" );
$basket = array_reverse($arr1);
print_r($basket);
?>

Output

Array ( [0] => three [1] => two [2] => one ) 
Test