dennismonsewicz Posted August 5, 2008 Share Posted August 5, 2008 How would you say if($var == 2 AND/OR $var == 3) obviously the and/or being the logicals Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted August 5, 2008 Share Posted August 5, 2008 if both need to be true if($var == 2 AND $var == 3){ do this } if at least one needs to be true: if($var == 2 OR $var == 3){ do this } Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted August 5, 2008 Author Share Posted August 5, 2008 hmmm... i got that i was just wondering if there was anyway of doing it within the same if statement Quote Link to comment Share on other sites More sharing options...
unidox Posted August 5, 2008 Share Posted August 5, 2008 if (($var2 == 2 OR $var == 3) OR ($var == 2 AND $var == 3)) { } Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted August 5, 2008 Share Posted August 5, 2008 I've been wondering about this myself.. Would it also then be possible to give the code choices? Like say if this event happens The code can either run this script or this script or this script which ever one it chooses. Maybe if you matched it up with a math.random sort of thing? Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted August 5, 2008 Share Posted August 5, 2008 no. a script cannot "choose". Its programmed to do a certain thing. Once it finds that it has the permissions to go on, it will, with the first thing. for example, this is pointless: if (($var == 2 OR $var == 3) OR ($var == 2 AND $var == 3)) { } Main problem here: a $var cannot equal 2 things at the same time. Unless its in an array, in which case you would use array functions, not "==" Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted August 5, 2008 Author Share Posted August 5, 2008 ok thanks guys! Quote Link to comment Share on other sites More sharing options...
.josh Posted August 5, 2008 Share Posted August 5, 2008 exactly. ($var == 2 AND $var == 3) would break down because $var cannot equal two things at the same time. Now if you were to do this: $var = 5; if(($var > 4) AND ($var < 6)) { // condition is true, code here will execute } elseif (($var > 4) OR ($var < 6)) { // condition is true, but will not get executed because the first condition was true } But you could do this: $var = 10; if(($var > 4) AND ($var < 6)) { // condition is not true, code here won't execute } elseif (($var > 4) OR ($var < 6)) { // condition is true, code will execute } Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted August 5, 2008 Share Posted August 5, 2008 Quick Question...does AND and OR work now? I always used to use && and ||...Am I living in the past? Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted August 5, 2008 Share Posted August 5, 2008 all of those work Quote Link to comment Share on other sites More sharing options...
.josh Posted August 5, 2008 Share Posted August 5, 2008 okay && is the same as AND and || is the same as OR. The only difference between them is the order in which PHP will parse them mathematically. Kind of like how division will always be performed before multiplication, then addition, then subtraction. && will take precedence over AND and || will take precedence over OR so if you used both of && and AND in the same condition, && will be evaluated first. Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted August 5, 2008 Share Posted August 5, 2008 Ah ok, cheers How long has AND and OR been around then? I'd never heard of them in PHP :S EDIT: well, except in or die(mysql_error()); and similar. Quote Link to comment Share on other sites More sharing options...
.josh Posted August 5, 2008 Share Posted August 5, 2008 Don't know but I first got into PHP a little over 4 years ago and it was there at least that long ago. Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted August 5, 2008 Share Posted August 5, 2008 Hah, much longer than I've been doing PHP then (9 months?) Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 5, 2008 Share Posted August 5, 2008 Don't know but I first got into PHP a little over 4 years ago and it was there at least that long ago. I've been doing PHP for even longer than that and they've been in it since I started too. =P Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted August 5, 2008 Share Posted August 5, 2008 you mixed a math.random in there tho it would be able to choose. cuase you could setup a bunch of different cases.. or a bunch of Dynamic cases that use other data and say $action=math.random or something then say switch($action) case '1': //do this option break; case '2': //do this break; ect... Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted August 5, 2008 Author Share Posted August 5, 2008 WOW I didn't realize I had asked a loaded question! ROFL Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted August 5, 2008 Share Posted August 5, 2008 lol oh but you have lmao... This is very interesting to me tho.. I wana try and make some kind of application that thinks now. At least thinks alil bit. Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted August 5, 2008 Author Share Posted August 5, 2008 the question came up when I was doing some server side validation... Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 5, 2008 Share Posted August 5, 2008 Well, just to reinforce the point, you can't have an and/or because it logically makes no sense. It's the equivalent of OR technically. >_> Quote Link to comment Share on other sites More sharing options...
.josh Posted August 5, 2008 Share Posted August 5, 2008 Well, just to reinforce the point, you can't have an and/or because it logically makes no sense. It's the equivalent of OR technically. >_> Not necessarily. OR: a b X X true X O true O X true O O false yes, if you do a condition with an OR, it will evaluate true if both are true, making it like an AND, but you would not be able to separate the logic. For instance, if you wanted to do one thing if either one of them would be true (OR), but you wanted to do something else if both were true (AND), you could not do that with an OR by itself. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 5, 2008 Share Posted August 5, 2008 Well, and/or is not a valid logic operator, but in actuality it would function as an OR. If you wanted to separate it out, that's a different story. >_> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.