Is it best practice to include the counter increment within the if statement in PHP loops?

It is not best practice to include the counter increment within the if statement in PHP loops as it can lead to confusion and potential errors. It is recommended to separate the counter increment outside of the if statement to ensure clarity and maintainability of the code.

// Incorrect way with counter increment within if statement
$counter = 0;
while ($counter < 10) {
    if ($counter % 2 == 0) {
        echo $counter . " is even";
    }
    $counter++; // Increment within if statement
}

// Correct way with counter increment outside if statement
$counter = 0;
while ($counter < 10) {
    if ($counter % 2 == 0) {
        echo $counter . " is even";
    }
    $counter++; // Increment outside if statement
}