Page 1 of 1

And/Or

Posted: Sun Jul 01, 2007 12:31 pm
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

Posted: Sun Jul 01, 2007 12:33 pm
by Oren
You mean bitwise?

Posted: Sun Jul 01, 2007 12:35 pm
by kaszu
http://www.php.net/manual/en/language.operators.php

If ($cart == 2 && $user = 4)
If ($cart == 2 || $user = 4)

Posted: Sun Jul 01, 2007 1:08 pm
by miro_igov
$user == 4

Posted: Sun Jul 01, 2007 3:09 pm
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

Posted: Sun Jul 01, 2007 3:12 pm
by idevlin
No, you have to do them separately.

Code: Select all

(($x==$y) && (($r==2 || $r==4)))

Posted: Sun Jul 01, 2007 3:13 pm
by Weirdan

Code: Select all

if ($x == $y && ($r == 2 || $r == 4)) {}
if ($x == $y && in_array($r, array(2,4))) {}

Posted: Sun Jul 01, 2007 3:13 pm
by feyd

Code: Select all

$x == $y and $r == 2 || $r == 4
Same result as what idevlin wrote. ;)

Posted: Sun Jul 01, 2007 3:15 pm
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.