Crusader Posted December 17, 2006 Share Posted December 17, 2006 I have eight variables stored, for example:$first, $second, $third, $fourth, $fifth, $sixth, $seventh, $eigthIs there an easier way to determine if two or more of them are greater than zero other than looping through it to make all the possible combinations?Thanks. Link to comment https://forums.phpfreaks.com/topic/30966-solved-if-two-or-more-are-greater-than-zero/ Share on other sites More sharing options...
Orio Posted December 17, 2006 Share Posted December 17, 2006 I dont think there's another way. I may be wrong, but that's what I would do:[code]<?php$positives = 0;$numbers = array($first, $second, $third, $fourth, $fifth, $sixth, $seventh, $eigth);foreach ($numbers as $num){ if($num > 0) $positives ++;}echo "There are ".$positives." positive numbers.";?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/30966-solved-if-two-or-more-are-greater-than-zero/#findComment-143020 Share on other sites More sharing options...
Crusader Posted December 18, 2006 Author Share Posted December 18, 2006 Worked perfectly, thank you! Link to comment https://forums.phpfreaks.com/topic/30966-solved-if-two-or-more-are-greater-than-zero/#findComment-143482 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.