PHP Break

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

PHP Break: inside loop

Let’s see a simple example to break the execution of for loop if value of i is equal to 5.

Output:

PHP Break: inside inner loop

The PHP break statement breaks the execution of inner loop only.

Output:

PHP Break: inside switch statement

The PHP break statement breaks the flow of switch case also.

Output:

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *