Switch case with three parameters?

前端 未结 7 1580
野趣味
野趣味 2020-12-17 20:49

Is it possible to use three parameters in switch-case, like this:

switch($var1, $var2, $var3){
    case true, false, false:
        echo \"Hello\";
        b         


        
7条回答
  •  旧时难觅i
    2020-12-17 21:26

    Another option is to create a function that maps three parameters to an integer and use that in the switch statement.

    function MapBool($var1, $var2, $var3){
        // ...
    }
    
    switch(MapBool($var1, $var2, $var3)) {
        case 0: 
            echo "Hello";
            break;
       // ...
    
    }
    

提交回复
热议问题