Skip to content
Advertisement

Can a switch statement take two arguments?

is it posible for a PHP switch statement to take 2 arguements? For example:

switch (firstVal, secondVal){

    case firstVal == "YN" && secondVal == "NN":
    thisDesc = "this is the outcome: YN and NN";
    break;

    case firstVal == "YY" && secondVal == "NN":
    thisDesc = "this is the outcome: YY and NN";
    break;
}

Many thanks, I haven’t done PHP in years!

Advertisement

Answer

No, but if your case is as simple as what you have, just concatenate the two inputs and test for the concatenated values:

switch ($firstval . $secondval) {
 case "YNNN": ...
 case "YYNN": ...
}
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement