What potential pitfalls should PHP beginners be aware of when working with loops in PHP?

One potential pitfall for PHP beginners when working with loops is forgetting to increment the loop counter variable properly. This can result in an infinite loop that consumes system resources and causes the script to hang. To avoid this issue, always remember to increment the loop counter within the loop body.

// Incorrect way to loop through an array
$numbers = [1, 2, 3, 4, 5];
$count = count($numbers);
for ($i = 0; $i < $count; ) {
    echo $numbers[$i] . " ";
}

// Correct way to loop through an array
$numbers = [1, 2, 3, 4, 5];
$count = count($numbers);
for ($i = 0; $i < $count; $i++) {
    echo $numbers[$i] . " ";
}