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; }
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;
}
1 answer