PHP array_reverse() function

PHP array_replace_recursive() function
PHP array_search() function

The array_reverse function reverses the elements of the given array and returns them. For instance, the first element of the array will appear at the last and the last will appear at the first applying this transition to the elements in between.

What is the syntax of the array_reverse function in PHP?

array_reverse(array, preserve)
ParametersDetails
arrayThe array to reverse the elements of – Required
preserveBoolean parameter – When set to true: Preserve the keys of the array while reversing. When set to false: keys are not preserved while reversing – Optional
array_reverse function in PHP

Example of array_reverse function

<?php
$arr=array("Suzuki","CD70",array("Honda","Toyota"));
$arr_reversed=array_reverse($arr);
$arr_reversed_preserved=array_reverse($arr,true);

print_r($arr);
print_r($arr_reverse);
print_r($arr_reversed_preserved);
?>

In the above example, we print the original array, reversed array, and the reversed array with preserved parameter set to true. Run this script to have the best understanding of the array_reverse function.

PHP array_replace_recursive() function
PHP array_search() function
en English
X
Scroll to Top