How to use break statement in switch inside a while loop in PHP

1 Answer

0 votes
$i = 1;
while($i++) 
{
    switch($i) 
    {
        case 3:
            echo "i = 3<br />";
            break 1;  // Exit from the switch
        case 7:
            echo "i = 7<br />";
            break 2;  // Exit from the switch and the while
        default:
            break;
    }
}

 
/*
run: 

i = 3
i = 7

*/

 



answered Jun 2, 2016 by avibootz

Related questions

1 answer 230 views
1 answer 187 views
1 answer 141 views
1 answer 202 views
1 answer 227 views
1 answer 88 views
...