Reverse Array with array_reverse()
Write a PHP function that takes an array and returns a new array with elements in reverse order using array_reverse().
array_reverse() is a PHP function that returns a new array with the order of elements reversed. Numeric keys are re-indexed by default, while string keys are preserved. An optional second parameter ($preserve_keys) can be set to true to preserve all keys.
This is the standard PHP way to reverse array order without writing manual loops. It is commonly used for reversing sorted results, implementing LIFO behavior, and processing data in reverse chronological order.
Time complexity is O(n) where n is the array length. The function creates a new array by copying elements in reverse order.
Example Input & Output
Simple reversal
Empty array
Three numbers reversed
Single element
String array
Algorithm Flow

Solution Approach
Best Answers
<?php
function solution($arr) {
return array_reverse($arr);
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
