Are there any alternative methods to achieve the same outcome as reversing the order of values in an array without using array_reverse() in PHP?

One alternative method to achieve the same outcome as reversing the order of values in an array without using array_reverse() in PHP is by iterating through the array and swapping values from the beginning to the end and vice versa until reaching the middle of the array.

function reverseArray($arr) {
    $length = count($arr);
    for ($i = 0; $i < $length / 2; $i++) {
        $temp = $arr[$i];
        $arr[$i] = $arr[$length - $i - 1];
        $arr[$length - $i - 1] = $temp;
    }
    return $arr;
}

// Example usage
$array = [1, 2, 3, 4, 5];
$reversedArray = reverseArray($array);
print_r($reversedArray); // Output: [5, 4, 3, 2, 1]