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:

Spread the love

One comment

  1. An impressive share, I just given this onto a colleague who was doing a little analysis on this. And he in fact bought me breakfast because I found it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I feel strongly about it and love reading more on this topic. If possible, as you become expertise, would you mind updating your blog with more details? It is highly helpful for me. Big thumb up for this blog post!

Leave a Reply

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