PHP comparison with multiple conditions
When you use ||
, if any of them satisfies, it will be executed. When you don't want both of them satisfied, you need to use &&
. Should be -
if($site!=1 && $site!=4)
It will check both conditions, i.e. $site
not equal 1
or 4
.
OR you can use in_array
-
if(!in_array($site, array(1, 4)))
It currently checks $site
for 1
or not first if it will not enter the state and ignore the rest of the conditions. Therefore, 4
it will not be checked for.
source to share