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; }
posted on 13.06.2020 at 18:08
0pnshow more

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.";
posted on 14.06.2020 at 17:32
0pnshow more
share on facebookshare on twitter
2020 AnswerTabsTermsContact us
This site uses cookies to improve your experience, for analytics and ads. By continuing to browse this site you agree to our use of cookies.