What potential pitfalls should be considered when using foreach loops to iterate over arrays in PHP?

One potential pitfall when using foreach loops to iterate over arrays in PHP is modifying the array within the loop, which can lead to unexpected behavior. To avoid this issue, it is recommended to create a copy of the array before iterating over it to prevent unintended modifications.

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

foreach ($copyArray as $value) {
    // Perform operations on $value
}