What potential pitfalls should be considered when passing large arrays as parameters in PHP functions, especially in terms of memory usage?
Passing large arrays as parameters in PHP functions can lead to increased memory usage, especially if the array is copied when passed. To mitigate this, consider passing arrays by reference using the `&` symbol to avoid unnecessary copies of the array. This can help reduce memory usage when working with large datasets.
// Passing array by reference to avoid unnecessary copying
function processArrayByReference(&$arr) {
// Function logic here
}
// Example of passing a large array by reference
$largeArray = range(1, 1000000);
processArrayByReference($largeArray);