Leadwing Posted April 14, 2008 Share Posted April 14, 2008 Hi there, Im fairly new to PHP... Is it possible to have something like: if variable1=true AND variable2=true echo "result1" elseif variable1=true AND variable2=false echo "result2" elseif variable1=false AND variable2=true echo "result3" elseif variable1=false AND variable2=false echo "result4" In reality there are more variables, but just so you understand. I dont know how to have multiple variables in a if statement... the "AND" Can i just use ";" or something? Thanks Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 14, 2008 Share Posted April 14, 2008 You can use AND or you can use &&. Most people would use &&: <?php $foo = 1; $bar = 10; if($foo==1 && $bar < 5){ echo 'result1'; }elseif($foo==1 && $bar > 10){ echo 'result2'; }else{ echo 'result3'; } ?> If you want an if statement to evaluate to true when one of two things are true, use OR (||): <?php $foo = 1; $bar = 2; if($foo==1 || $bar ==1){//note, this will be true when one or both of these statements are true. echo $result1; } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted April 14, 2008 Share Posted April 14, 2008 Yes, and its just as youve written it. <?php if ($variable1 AND $variable2) { echo "result1"; } elseif ($variable1 AND !$variable2) { echo "result2"; } elseif (!$variable1 AND $variable2) { echo "result3"; } elseif (!$variable1 AND !$variable2) { echo "result4"; } ?> Quote Link to comment Share on other sites More sharing options...
Leadwing Posted April 14, 2008 Author Share Posted April 14, 2008 Oh haha! Thanks guys! *love* 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.