Can it be used for looping inside the switch?
Yes and no
You need to move foreach outside switch
or inside the selector case
. I'm not sure why the switch () is even needed. Why not just do something for each module without running it through the switch?
And most languages ββdon't let you jump into inner blocks. Even when they do it, it's not a good practice.
source to share
Looks like some form of Duff device - but I don't think it's legal anywhere outside C.
source to share
You can of course use a loop inside the switch. However, you cannot do what you are trying to do there; it just doesn't work. And I don't see any point in that. Why not just have an array of module names as keys and then do
if ($modules[$p]) {
include $modules[$p];
} else {
// not found...
}
or something like that?
source to share
I don't think you can do such a thing: right away a switch statement, the only thing you can use is the case
or statement default
.
This is what you get, tells you: btw:
Parse error: syntax error, unexpected T_FOREACH, expecting T_CASE or T_DEFAULT or '}'
If you want a loop and swith, you have to either put the loop "arround" the entire switch statement, or "inside" a case case.
source to share