What are some potential pitfalls when using foreach loops in PHP to iterate over arrays?
One potential pitfall when using foreach loops in PHP to iterate over arrays is modifying the array being iterated within the loop. This can lead to unexpected behavior and errors. To avoid this issue, you can create a copy of the array before iterating over it.
// Create a copy of the array before iterating over it
$array = [1, 2, 3, 4];
$arrayCopy = $array;
foreach ($arrayCopy as $value) {
// Do something with $value
}