What are some potential pitfalls to avoid when using for loops in PHP?

One potential pitfall to avoid when using for loops in PHP is off-by-one errors, where the loop either runs one too many times or one too few times. To prevent this, make sure to carefully set the loop conditions and counter variables. Another pitfall is modifying the loop counter variable within the loop, which can lead to unexpected behavior. It's best practice to avoid changing the loop counter variable inside the loop to maintain clarity and prevent errors.

// Example of avoiding off-by-one errors in a for loop
for ($i = 0; $i < 5; $i++) {
    // loop body
}