sina Posted August 1, 2007 Share Posted August 1, 2007 I'm really new to PHP, just trying to develop a pretty simple app. For example, I have IF ((isset($_POST['submit']))&&(($_POST['zipd'])!="")) {} But I Want to add another condition that would trigger the same IF section. But is there an easy way to do that in php? Quote Link to comment https://forums.phpfreaks.com/topic/62768-solved-is-there-no-way-of-doing-if-ab-or-cd/ Share on other sites More sharing options...
Nakor Posted August 1, 2007 Share Posted August 1, 2007 I'm not 100% sure what you're asking but I assume you are asking how to structure if statements? If so all you need to do is place your parentheses properly. Example: if ( ($condition1 || $condition2) && ($condition3 || $condition4) ) Quote Link to comment https://forums.phpfreaks.com/topic/62768-solved-is-there-no-way-of-doing-if-ab-or-cd/#findComment-312492 Share on other sites More sharing options...
btherl Posted August 1, 2007 Share Posted August 1, 2007 You can do this: if ( (isset($_POST['submit']) && $_POST['zipd']!="") || $something_else) {} The new lines are not necessary, I just added them for clarity. I also removed some unnecessary brackets. PHP knows that && and || should always seperate comparisons. Quote Link to comment https://forums.phpfreaks.com/topic/62768-solved-is-there-no-way-of-doing-if-ab-or-cd/#findComment-312493 Share on other sites More sharing options...
sina Posted August 1, 2007 Author Share Posted August 1, 2007 Got it. Learning a new language is just confusing me. Makes perfect sense, don't know why I didn't recognize that && before. Thanks a million! Quote Link to comment https://forums.phpfreaks.com/topic/62768-solved-is-there-no-way-of-doing-if-ab-or-cd/#findComment-312495 Share on other sites More sharing options...
teng84 Posted August 1, 2007 Share Posted August 1, 2007 if you have tons to be condition use in_array $array=array('a','c',......etc); if (in_array('a',$array)) { //do something } something like that Quote Link to comment https://forums.phpfreaks.com/topic/62768-solved-is-there-no-way-of-doing-if-ab-or-cd/#findComment-312496 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.