How can the switch statement be used with two variables in PHP?

To use the switch statement with two variables in PHP, you can concatenate the two variables into a single string and then use that string as the case value. This allows you to switch on a combination of the two variables.

$var1 = 1;
$var2 = 2;

$combined = $var1 . '-' . $var2;

switch ($combined) {
    case '1-1':
        echo "Both variables are 1";
        break;
    case '1-2':
        echo "Variable 1 is 1 and variable 2 is 2";
        break;
    default:
        echo "No matching case";
}