How can foreach be used to pass an array by reference in PHP?
When using foreach loop in PHP, the array elements are passed by value by default, meaning any modifications made to the array elements within the loop will not affect the original array. To pass the array by reference in a foreach loop, you can use the reference operator '&' before the $value variable in the loop declaration. This allows you to directly modify the original array elements within the loop.
$array = [1, 2, 3, 4, 5];
foreach ($array as &$value) {
$value *= 2;
}
print_r($array);