Triple equal operator fails when checking for one of variants but they are the same type

47 Views Asked by At
$type = 'bravo';

if ($type === ('alpha' || 'bravo')) {
    echo $type;
}

This never returns anything. Why this is happening?

2

There are 2 best solutions below

1
On

Try this:

if ($type === 'alpha' || $type === 'bravo') {
    echo $type;
}

You have to check values individually.

0
On

'alpha' || 'bravo' is boolean true not string 'bravo'