PHP array_reverse() Function
Last Updated : 17 Mar 2025
The array_reverse() function is a inbuilt function of PHP. The array_reverse( ) function is used to reverse the order of the elements in an array. This function was introduced in PHP 4.0.
Syntax
Parameter
| Parameter | Description | Is compulsory |
|---|---|---|
| array | Specifies an array. | compulsory |
| preserve_keys | Specify TRUE or FALSE whether function is preserved the array?s keys or not. The default value is FALSE. | Optional |
Return type
The array_reverse() function returns the reversed array.
Example 1
Output:
Array ( [0] => javatpoint [1] => 2 [2] => Array ( [0] => PHP [1] => JAVA ) ) Array ( [0] => Array ( [0] => PHP [1] => JAVA ) [1] => 2 [2] => javatpoint ) Array ( [2] => Array ( [0] => PHP [1] => JAVA ) [1] => 2 [0] => javatpoint )
Example 2
Output:
Array ([4] => 500 [3] => 400 [2] => 300 [1] => 200 [0] => 100) Array ([0] => 500 [1] => 400 [2] => 300 [3] => 200 [4] => 100)
Example 3
Output:
Array ( [c] => PYTHON [b] => JAVA [a] => PHP )
Example 4
Output:
Array ( [0] => PHP [1] => JAVA [2] => PERL [3] => PYTHON ) Array ( [3] => PYTHON [2] => PERL [1] => JAVA [0] => PHP )
Next TopicPhp-array-rsort-function