How can you efficiently reverse a range of values in PHP when dealing with a large value range, such as 100,000?

When dealing with a large value range, such as 100,000, efficiently reversing the values can be achieved by using a loop that iterates over half of the range and swaps the values at each end of the range. This approach minimizes the number of operations needed to reverse the range.

<?php
// Initialize the range of values
$range = range(1, 100000);

// Efficiently reverse the range of values
$length = count($range);
for ($i = 0; $i < $length / 2; $i++) {
    $temp = $range[$i];
    $range[$i] = $range[$length - $i - 1];
    $range[$length - $i - 1] = $temp;
}

// Output the reversed range of values
print_r($range);
?>