Share on Google+Share on Google+
PHP Break
Posted on: March 26, 2010 at 12:00 AM
Advertisement
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

Advertisement

Related Tags for PHP Break:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 26, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com