What are some best practices for incrementing variables in PHP loops?

When incrementing variables in PHP loops, it is important to ensure that the variable is incremented correctly to avoid infinite loops or incorrect results. One common mistake is not properly incrementing the variable inside the loop, leading to unexpected behavior. To avoid this, make sure to increment the variable within the loop according to the desired logic.

// Example of correctly incrementing a variable in a PHP loop
$counter = 0;

while ($counter < 10) {
    // Do something
    
    // Increment the counter
    $counter++;
}