What are the best practices for copying arrays before applying sorting functions in PHP to avoid unintended consequences?

When sorting arrays in PHP, it is important to make a copy of the original array before applying any sorting functions to avoid unintended consequences such as modifying the original array. This can be achieved by using the `array_slice` function to create a copy of the array that can be sorted independently.

// Original array
$originalArray = [3, 1, 2, 4];

// Create a copy of the original array
$copyArray = array_slice($originalArray, 0);

// Sort the copy array
sort($copyArray);

// Output the sorted copy array
print_r($copyArray);

// Original array remains unchanged
print_r($originalArray);