What potential issues can arise when trying to add an additional parameter to a sorting function in PHP?

When adding an additional parameter to a sorting function in PHP, the potential issue that can arise is that existing code that calls the sorting function may not provide the new parameter, leading to errors or unexpected behavior. To solve this, you can set a default value for the new parameter in the function definition, so that if the parameter is not provided, it will use the default value instead.

function customSort($array, $sortBy = 'asc') {
    if($sortBy === 'asc') {
        sort($array);
    } elseif($sortBy === 'desc') {
        rsort($array);
    } else {
        // Handle invalid sorting option
        echo "Invalid sorting option";
    }

    return $array;
}

// Usage example
$array = [3, 1, 2, 5, 4];
$sortedArray = customSort($array, 'desc');
print_r($sortedArray);