PHP array_reverse() Function

The array_reverse() function returns an array in the reverse order.

The array_reverse() function is used to reverse the order of the elements in an array.

PHP array_reverse() Function has the following syntax.

Parameter Description
array Required. Specifies an array
preserve Optional. Specifies if the function should preserve the keys of the array or not.

Possible values:

  • true
  • false

Syntax

 array_reverse(array,preserve) 

Example

$array = array("a"=>"Cooper","b"=>"Samuel","c"=>"James");
print_r(array_reverse($array));

Output

Array ( [c] => James [b] => Samuel [a] => Cooper ) 

Leave a Reply

Your email address will not be published. Required fields are marked *