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 234 views
1 answer 195 views
1 answer 144 views
1 answer 209 views
1 answer 231 views
1 answer 94 views
...