PHP switch statement - multiple cases for one function

When I am using PHP switch statement, how can I add multiple cases for the same function ? I am looking for equivalent of:

if( $value == 1 OR $value == 2 OR $value == 3 ) { $function; }
13 Jun 2020 at 06:08 PM
0pnshow more
StorStor
Hi,

To assign multiple switch() cases to one function, you can do this:

switch ($value) {
case 1:
case 2:
case 3:
echo "This will appear, when $value is equal to 1,2 or 3.";
break;
}
14 Jun 2020 at 05:32 PM
0pnshow more
TimTim
Share on FacebookShare on TwitterShare on LinkedInSend email
Follow us on Facebook & Twitter
2022 AnswerTabsTermsContact us