break statement do in PHP loops?break statement immediately stops the execution of the current loop and exits it.break with levels work in PHP?break to exit multiple nested loops at once. For example, break 2; exits two levels of loops.break 1; in a nested loop?break 1; exits only the innermost loop, which is the default behavior of break without a number.break with levels in switch statements in PHP?break with levels works in both loops and switch statements. It exits the specified number of enclosing loop or switch structures.for ($i = 1; $i <= 3; $i++) {
for ($j = 1; $j <= 3; $j++) {
if ($j == 2) {
break 2;
}
echo "$i$j ";
}
}11 . When $j equals 2, break 2; exits both loops immediately, so only 11 is printed.break 3; do inside three nested loops?break 3; exits three levels of loops, so it stops all three nested loops immediately.
break if no number is specified?By default, break exits only the innermost loop, which is level 1.
break 2; be used inside a single loop?If you use break with a level greater than the number of nested loops, PHP will issue a warning.
break in PHP?break can exit multiple nested loops by specifying a number after it.
break 0; in a loop?Using break 0; is invalid and causes a fatal error in PHP.
break statement with levels works in PHP nested loops.