How to terminate or break a loop in PHP?
By using break keyword in the loop, we can terminate or break a loop anywhere in PHP .
Example to break a PHP loop:
<?php
$months = array('jan', 'feb', 'mar', 'apr', 'stop', 'may');
foreach ($months as $month) {
if ($month == 'stop') {
break;
}
echo "$month<br />";
}
?>
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |