Break Statement In PHP

Break Statement

The break statement in PHP immediately terminated the loop without waiting to get back to test condition.
For example:


<?php

$counter=1;

for ($counter =0 ; $counter<=100 ; $counter++)
{
if ($counter==50)
break ;
echo $counter . "<br />" ;
}
?>

We see that in this code we use for loop to display the number 1 to 100 . but using break statement before the print statement stopped the loop when counter reached to 50 and loop is terminated.