What potential issues can arise when using foreach loops in PHP?

One potential issue that can arise when using foreach loops in PHP is modifying the array being iterated over within the loop. This can lead to unexpected behavior or errors. To solve this issue, you can create a copy of the array before iterating over it to avoid modifying the original array.

// Creating a copy of the array before iterating over it
$array = [1, 2, 3, 4, 5];
$copy = $array;

foreach ($copy as $value) {
    // Do something with $value
}