在PHP中使用逻辑运算符if / else [关闭]

Is it possible to use logical operators in the "then" part of the if/then statement in PHP?

This is my code:

if ($TMPL['duration'] == NULL) {
$TMPL['duration'] = ('120' or '124' or '114' or '138'); }
else {
$TMPL['duration'] = ''.$TMPL['duration']; }

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

Are you aiming for a switch?

switch($TMPL['duration']) {
    case NULL:
    case '120':
    case '124':
    case '114':
    case '138':
        <do stuff>
        break;
    default:
        $TMPL['duration'] = ''.$TMPL['duration'];
}

Also you can do something like this utilizing in_array:

if ($TMPL['duration'] === NULL
    || in_array($TMPL['duration'], array('120','124','114','138')) {
    // Do something if duration is NULL or matches any item in the array
} else {
    // Do something if duration is not NULL or does not match any item in array
}