Why does the code snippet provided always output a 1 at the end?
The issue with the provided code snippet is that the variable $i is being incremented inside the if statement, which causes the loop to always run once before checking the condition. To fix this, we should move the increment operation outside the if statement so that it is executed after the condition is checked. This way, the loop will only run when the condition is met.
$i = 0;
while ($i < 10) {
if ($i % 2 == 0) {
echo $i . "<br>";
}
$i++;
}