Solved

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

Posted on 2008-06-19
5
159 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now