Solved

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

Posted on 2008-06-19
5
162 Views
Last Modified: 2008-06-21
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
Comment
Question by:Ryan Bayne
  • 3
5 Comments
 
LVL 2

Expert Comment

by:JonMarkGo
ID: 21826366
Yes, || represents or and && represents and
0
 
LVL 2

Expert Comment

by:JonMarkGo
ID: 21826372
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
 
LVL 2

Accepted Solution

by:
JonMarkGo earned 150 total points
ID: 21826376
For example:  if ($auth == "yes" && ($access == "master" || $access == "member" || $access == "admin" || $access = "))
0
 
LVL 10

Expert Comment

by:Dxpert
ID: 21826385
Yes, you can use || or "OR" for a logical comparison.
http://us3.php.net/manual/en/language.operators.logical.php
0
 
LVL 2

Author Comment

by:Ryan Bayne
ID: 21827483
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question