Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple OR in php if() not seeming to respond properly. Tested array values and all. What am I doing wrong?

I am running a very simple if statement which works perfect until I add the two additional || (or) operators.

Here is my code:

if ($planDetails['Company']['name'] != 'company1'
|| $planDetails['PlanDetail']['name'] != 'pd-name1' 
|| $planDetails['PlanDetail']['name'] != 'pd-name2') { echo "TEST"; }

I've checked my array data and table values to ensure they are precise in the names etc.. And this is not kicking. What am I doing wrong? When I remove the additional 2 || options, the first argument works fine, so I know my logic is correct.

What in the name am I doing wrong here. Someone please set me straight!

like image 784
OldWest Avatar asked Dec 02 '22 03:12

OldWest


1 Answers

Well, what I read here is:

If $variable is not equal to A Or $variable is not equal to B
Then echo "TEST"

Since $variable cannot be equal to both A and B at the same time, it will always print "TEST".

Of course, the above refers to the last two conditions in your if.

like image 178
Jon Avatar answered Dec 04 '22 07:12

Jon