Advertisement
Google Ad Slot: content-top
PHP Break
The break statement is particularly useful when you need to stop loop execution based on a condition, preventing unnecessary iterations.
Using break in a for Loop
The break statement can be used to jump out of a for loop.
Example
<?php
for ($i = 1; $i <= 10; $i++) {
if ($i == 5) {
break; // Exits the loop when $i equals 5
}
echo "Number: $i<br>";
}
?>
Note
You can also use break statement in while, do...while and foreach loop.