unemployment Posted April 25, 2011 Share Posted April 25, 2011 What is the best way to say... If more than two of these if's are satisfied, do this... if ((isset($_POST['credentials'])) && ($_POST['credentials'] != $r['credentials'])) { $details = ''; update_user_actions(2, $details); } if ((isset($_POST['specialties'])) && ($_POST['specialties'] != $r['specialties'])) { $details = ''; update_user_actions(3, $details); } if ((isset($_POST['personalweb'])) && ($_POST['personalweb'] != $r['personalweb'])) { $details = $_POST['personalweb']; update_user_actions(4, $details); } Link to comment https://forums.phpfreaks.com/topic/234619-multiple-conditionals/ Share on other sites More sharing options...
Fadion Posted April 25, 2011 Share Posted April 25, 2011 The quick way would be adding a counter that gets incremented for every satisfied condition. Something like this: <?php $if_count = 0; if ((isset($_POST['credentials'])) && ($_POST['credentials'] != $r['credentials'])) { $details = ''; update_user_actions(2, $details); $if_count++; } if ((isset($_POST['specialties'])) && ($_POST['specialties'] != $r['specialties'])) { $details = ''; update_user_actions(3, $details); $if_count++; } if ((isset($_POST['personalweb'])) && ($_POST['personalweb'] != $r['personalweb'])) { $details = $_POST['personalweb']; update_user_actions(4, $details); $if_count++; } if ($if_count >= 2) { //do this } ?> If $if_count = 0, no condition is satisfied. If $if_count = 1, 1 condition is satisfied and so on up to 3 (all conditions satisfied). Link to comment https://forums.phpfreaks.com/topic/234619-multiple-conditionals/#findComment-1205717 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.