• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

Can you use or | to describe multiple choices for a single part of an argument in PHP

Basically I'm trying this...

                  if ($auth == "yes" && $access == "master" || $access == "member")

and later I'm going to use...

                  if ($auth == "yes" && $access == "master" || $access == "member" || $access == "admin" || $access = ")

Is this alright? I'm testing it and it seems ok but thought I'd run it by someone.

Ryan Bayne
Ryan Bayne
  • 3
1 Solution
Yes, || represents or and && represents and
Be sure you understand the logic order of operations. If you don't or want to be more specific, I would suggest using parentheses to separate the parsing of each group of logic statements.
For example:  if ($auth == "yes" && ($access == "master" || $access == "member" || $access == "admin" || $access = "))
Yes, you can use || or "OR" for a logical comparison.
Ryan BayneWordPress DeveloperAuthor Commented:
I maybe was not clear the | | I know about and I used or recently without thinking realising it works

what I was trying to ask is if there is an alternative because I didnt think the logic was sound as you say JonMarkGo  it should be...

if ($auth == "yes" && ($access == "master" || $access == "member" || $access == "admin" || $access = "))

I fail to keep in mind what brackets can do in coding but thats my answer so cheers all
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now