When a function returns an array in PHP, is the returned array copied and created outside of the function's namespace or does it continue to exist within the function?

When a function returns an array in PHP, the returned array is copied and created outside of the function's namespace. This means that any changes made to the returned array outside of the function will not affect the original array within the function. To solve this issue and have changes reflect in the original array, you can return the array by reference using the `&` symbol before the function name.

function &returnArrayByReference() {
    $array = [1, 2, 3];
    return $array;
}

$originalArray = &returnArrayByReference();
$originalArray[] = 4;

print_r($originalArray); // Output: Array([0] => 1, [1] => 2, [2] => 3, [3] => 4)