[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 168
  • 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.

cheers
0
Ryan Bayne
Asked:
Ryan Bayne
  • 3
1 Solution
 
JonMarkGoCommented:
Yes, || represents or and && represents and
0
 
JonMarkGoCommented:
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.
0
 
JonMarkGoCommented:
For example:  if ($auth == "yes" && ($access == "master" || $access == "member" || $access == "admin" || $access = "))
0
 
DxpertCommented:
Yes, you can use || or "OR" for a logical comparison.
http://us3.php.net/manual/en/language.operators.logical.php
0
 
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
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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