What are the potential pitfalls of iterating over an array in PHP using foreach loops?
One potential pitfall of iterating over an array in PHP using foreach loops is modifying the array during iteration, which can lead to unexpected behavior or errors. To avoid this issue, you can create a copy of the array before iterating over it, ensuring that the original array remains unchanged.
// Create a copy of the array before iterating over it
$array = [1, 2, 3, 4, 5];
$arrayCopy = $array;
foreach ($arrayCopy as $value) {
// Perform operations on $value
}