Are there best practices for initializing and incrementing variables in PHP loops like while and for?

When initializing and incrementing variables in PHP loops like while and for, it is best practice to do so within the loop itself to ensure that the variables are properly reset and incremented with each iteration. This helps to avoid potential issues with variable scope and unintended side effects.

// Example of initializing and incrementing a variable in a for loop
for ($i = 0; $i < 10; $i++) {
    // Loop logic here
}

// Example of initializing and incrementing a variable in a while loop
$i = 0;
while ($i < 10) {
    // Loop logic here
    $i++;
}