What are some best practices for handling array values and references in PHP?

When working with array values and references in PHP, it's important to understand the difference between passing arrays by value and by reference. To ensure that changes made to an array within a function are reflected outside of the function, you should pass the array by reference using the "&" symbol. Additionally, be mindful of the scope of your arrays to avoid unexpected behavior.

// Passing an array by reference to modify its values
function modifyArrayValues(&$array) {
    foreach ($array as $key => $value) {
        $array[$key] = $value * 2;
    }
}

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