What potential pitfalls can arise from not using curly braces in a foreach loop in PHP?

When not using curly braces in a foreach loop in PHP, only the next statement after the loop will be considered part of the loop. This can lead to unexpected behavior and bugs if multiple statements are intended to be executed within the loop. To avoid this issue, always use curly braces to explicitly define the block of code to be executed within the loop.

// Incorrect way without curly braces
foreach ($array as $item)
    echo $item;
    echo " "; // This statement is not part of the loop

// Correct way with curly braces
foreach ($array as $item) {
    echo $item;
    echo " "; // This statement is part of the loop
}