meltingpoint Posted January 28, 2012 Share Posted January 28, 2012 This works: if($ABC == 'Yes' and $X != $Y){ echo "Error"; exit(); } I need to evaluate one more set of variables in this statement like so; This does not work: if($ABC == 'Yes' and $X != $Y or $Z != $Y){ echo "Error"; exit(); } So basically I need to echo an error if $ABC == Yes and both $X and $Z do not equal $Y If gives an error because it is obviously not correct. I do not know how to make it correct. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/255923-multiple-if-in-one-statement/ Share on other sites More sharing options...
darkfreaks Posted January 28, 2012 Share Posted January 28, 2012 //fixed with || which will return both true and false and just not false if($ABC == 'Yes' and $X != $Y || $Z != $Y){ echo "Error"; exit(); } Link to comment https://forums.phpfreaks.com/topic/255923-multiple-if-in-one-statement/#findComment-1311884 Share on other sites More sharing options...
Pikachu2000 Posted January 28, 2012 Share Posted January 28, 2012 You had the logic you need written out already: $ABC == Yes and both $X and $Z do not equal $Y . . . if( $ABC == 'Yes' && $X != $Y && $Z != $Y) { Edit: fixed tags . . . Link to comment https://forums.phpfreaks.com/topic/255923-multiple-if-in-one-statement/#findComment-1311967 Share on other sites More sharing options...
meltingpoint Posted January 28, 2012 Author Share Posted January 28, 2012 Thanks- stared too long at the problem. Cheers- Link to comment https://forums.phpfreaks.com/topic/255923-multiple-if-in-one-statement/#findComment-1311979 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.