What potential issue arises when using foreach with an array in PHP?
When using foreach with an array in PHP, a potential issue that may arise is modifying the array within the loop. This can lead to unexpected behavior or errors because foreach operates on a copy of the array rather than the actual array itself. To solve this issue, you can use a reference variable in the foreach loop declaration, which allows you to directly modify the original array.
$array = [1, 2, 3, 4, 5];
foreach ($array as &$value) {
$value *= 2;
}
unset($value); // unset the reference variable
print_r($array);