Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
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 …

863 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

25 Experts available now in Live!

Get 1:1 Help Now