And/Or

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

And/Or

Post by tecktalkcm0391 »

How can you do a if statement using and/or any simple way like &| ?

How would you do this:
If $cart = 2 and/or $user = 4
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

You mean bitwise?
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Post by kaszu »

http://www.php.net/manual/en/language.operators.php

If ($cart == 2 && $user = 4)
If ($cart == 2 || $user = 4)
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

$user == 4
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

kaszu wrote:http://www.php.net/manual/en/language.operators.php

If ($cart == 2 && $user = 4)
If ($cart == 2 || $user = 4)
I meant doing them together. is there any simpler way to do if x==y and r==2 and/or 4
User avatar
idevlin
Forum Commoner
Posts: 78
Joined: Tue Jun 26, 2007 1:10 pm
Location: Cambridge, UK

Post by idevlin »

No, you have to do them separately.

Code: Select all

(($x==$y) && (($r==2 || $r==4)))
Last edited by idevlin on Sun Jul 01, 2007 3:16 pm, edited 2 times in total.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

if ($x == $y && ($r == 2 || $r == 4)) {}
if ($x == $y && in_array($r, array(2,4))) {}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$x == $y and $r == 2 || $r == 4
Same result as what idevlin wrote. ;)
User avatar
idevlin
Forum Commoner
Posts: 78
Joined: Tue Jun 26, 2007 1:10 pm
Location: Cambridge, UK

Post by idevlin »

feyd wrote:

Code: Select all

$x == $y and $r == 2 || $r == 4
Same result as what idevlin wrote. ;)
Hehe although mine seems to have disappeared? :?

**EDIT**
Goddamn it, I selected nearly everything and meant to copy it but replaced it with "c" instead. Not quite got the CTRL-C combination right there ;-). Fixed now.
Post Reply