In PHP, While using a switch case loop, can i use the for loop for iterating the cases?
for example
switch .....
foreach($xyz as $abc)
{
CASE:$abc
}
default;
UPDATE
I am fetching the value from DB, this value is name of table, by using “case” I want to execute a particular query according to the table name..
Is this possible?
You probably just want to put the
switchstatement into theforeach?Alternatively, a switch isn’t that easy to read, consider going away from a
switchand using an array-poweredif, especially if you could dynamically create what you want to do eachcase:That’s a lot more readable, even if your array has a lot of elements.