How does variable scope affect the manipulation of arrays within PHP functions?

Variable scope in PHP affects the manipulation of arrays within functions because variables declared inside a function are typically local to that function, meaning they are not accessible outside of it. To manipulate an array within a function and have those changes reflected outside of the function, you can pass the array as a parameter by reference or return the modified array from the function.

<?php
// Example of passing array by reference to manipulate it within a function
function manipulateArray(&$arr) {
    $arr[] = "new element";
}

$array = [1, 2, 3];
manipulateArray($array);
print_r($array); // Output: Array ( [0] => 1 [1] => 2 [2] => 3 [3] => new element )
?>