PHP Break Loop: Exit Loops Instantly
In PHP, the break keyword can be used to exit a loop. When the break keyword is executed, the loop will immediately end, and the program will continue executing the code after the loop. For example:
for ($i = 0; $i < 10; $i++) {
if ($i == 5) {
break;
}
echo $i . "<br>";
}
In the example above, when the value of $i is equal to 5, the break keyword will be executed, and the loop will immediately terminate, resulting in the output:
0
1
2
3
4