Go to another case in the PHP switch statement

Let's say I have something like this:

switch ($_GET['func']) { case 'foo': dobar(); break; case 'orange': if ($_GET['aubergine'] == 'catdog') { // **DO DEFAULT OPTION** } else { dosomethingElse(); } break; default: doDefault(); } 

How can I go to the default case from the marked location in case 'orange' ?

+7
source share
2 answers

Try:

 switch($_GET['func']) { case 'foo': dobar(); break; case 'orange': if($_GET['aubergine'] != 'catdog') { dosomethingElse(); break; } default: doDefault(); } 
+9
source

Yo dawg, you can use the cool new goto function.

 <?php $func = "orange"; function doDefault() { echo "yeehaw!"; return; } function dobar() { return; } function dosomethingElse() { return; } switch ($func) { case 'foo': dobar(); break; case 'orange': if (true) { goto defaultlabel; } else { dosomethingElse(); } break; default: defaultlabel: doDefault(); } 
+9
source

All Articles