Break out out forloop but within switch statement php Break out out forloop but within switch statement php php php

Break out out forloop but within switch statement php


from the manual (break)

break accepts an optional numeric argument which tells it how many nested enclosing structures are to be broken out of.


The accepted Answer has no practical example let me share with you.

break 2 

means exit from both loop and switch.

$i = 0;while (++$i) {    switch ($i) {    case 5:        echo "At 5<br />\n";        break 1;  /* Exit only the switch. */    case 10:        echo "At 10; quitting<br />\n";        break 2;  /* Exit the switch and the while. */    default:        break;    }}


break 2;

break x will break out of that many levels