Break in PHP

Advertisements

Do While Loop in PHP Switch Case in PHP

Break Statement in PHP

PHP break statement breaks the execution of current for, while, do-while, switch and for-each loop. If you use break inside inner loop, it breaks the execution of inner loop only..

Syntax

jump statement;  
break;  

PHP Break inside loop

Example of break in php

<?php

for($i=1;$i<=10;$i++)
{  
echo "$i <br/>";  
if($i==5)
{  
break;  
}  
}  

?>

Output

1 2 3 4 5

PHP Break inside inner loop

Example break in php

<?php

for($i=1;$i<=3;$i++)
{
 for($j=1;$j<=3;$j++)
 {
  echo "$i   $j<br/>";
  if($i==2 && $j==2)
  {
   break;
  }
 }
}

?>

Output

1 1 1 2 1 3 2 1 2 2 3 1 3 2 3 3

PHP Break: inside switch statement

Example break in php

<?php

$num=5;    
switch($num){    
case 1:    
echo("Monday");    
break;    
case 2:    
echo("Tuesday");    
break;    
case 3:    
echo("Wednasday");    
break;
case 4:    
echo("Thrusday");    
break;
case 5:    
echo("Friday");    
break;
case 6:    
echo("Sateday");    
break;
case 7:    
echo("Sunday");    
break;

?>

Output

Friday

Do While Loop in PHP Switch Case in PHP

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements