PHP OR Statement

I have a php page that I need to check if variables are equal to.  I'm writing this wrong.

<?php
if(($bike_state != "18") || ($bike_state != '32') || ($bike_state != '48') || ($bike_state != '50')) { }
?>

Open in new window

LVL 8
rgranlundAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brian TaoSenior Business Solutions ConsultantCommented:
If you're trying to do something when $bike_state is not any of "18", "32", "48" and "50", you should use &&.

And if you want to do something when $bike_state IS one of them, then you should change != to == (and leave the || unchanged)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgranlundAuthor Commented:
Thanks Tao!
justaphaseCommented:
If you're trying check if it's equal then you should try this...:
<?php 
$bike_state = 32;
if(($bike_state == 18) || ($bike_state == 32) || ($bike_state == 48) || ($bike_state == 50)) { echo "bike_state is equal to 18 or 32 or 48 or 50"; }
?>

Open in new window

Brian TaoSenior Business Solutions ConsultantCommented:
Glad that I could help.  Thanks for the points.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.