[Solved] Using Logical Operators in PHP if/else [closed]


Use else if.

$a = 1;

if($a === 1) {
    // do something
} else if ($a === 2) {
    // do something else    
}

Note that in most case the switch statement is better for that, like:

switch($a) {
    case 1:
        // do something
        break;

    case 2:
        // do something else
        break;
}

or:

switch(TRUE) {
    case $a === 1 :
        // do something else    
        break;

    case $b === 2 :
        // do something else
        break;
}

2

solved Using Logical Operators in PHP if/else [closed]