PHP Loops Interview Questions & Answers
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 />";
}
?>