PHP Break
Posted on: March 26, 2010 at 12:00 AM
In this tutorial we will study about break statement, break statement is generally used when need to discontinue or break a loop. Examples in this tutorial will make it more clear.

Break Control Structure:

Break is a special kind of control structure which helps us to break any loop or sequence, like if we want to break the flow of any loop (for, while etc) then we can use break statement, generally we need if control structure to implement .

If you want to break multiple control structure then we need to provide numeric argument along with break statement, example is given below:

Example:

<?php

for($a=1;$a<10;$a++)

{

if($a==5)

break;

else

echo "$a\t";

}

?>

Output:

1 2 3 4

Example:

<?php

$arr=array(1,2,3,4,5);

foreach($arr as $val):

if($val==4)break;

echo $val."<br/>";

endforeach;

?>

Output:

1
2
3

Related Tags for PHP Break:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.