How can the use of the & symbol in PHP function parameters affect the scope of variables?

When using the & symbol in PHP function parameters, it indicates that the parameter is passed by reference rather than by value. This means that any changes made to the parameter within the function will also affect the variable outside of the function, as they are referencing the same memory location. To avoid unintended side effects or scope-related issues, it's important to be mindful of when to use the & symbol in function parameters.

// Incorrect usage of & symbol in function parameters
function increment(&$num) {
    $num++;
}

$number = 5;
increment($number);
echo $number; // Output: 6

// Correct usage without the & symbol
function increment($num) {
    $num++;
    return $num;
}

$number = 5;
$number = increment($number);
echo $number; // Output: 5