What potential pitfalls should be considered when using rsort() to sort an array in PHP?

One potential pitfall when using rsort() to sort an array in PHP is that it modifies the original array directly, which may lead to unexpected results if the original array needs to be preserved. To avoid this issue, you can create a copy of the array before sorting it using rsort().

// Create a copy of the original array
$originalArray = [3, 1, 2];
$sortedArray = $originalArray;

// Sort the copied array in reverse order
rsort($sortedArray);

// Output the sorted array
print_r($sortedArray);