papaface Posted September 13, 2007 Share Posted September 13, 2007 Hello, I have this code: $numbers = array("04","13","18","21","30","46","(05)"); foreach ($data as $key => $value) { if ($data[$key][5] == $numbers[0] && $data[$key][6] == $numbers[1] && $data[$key][7] == $numbers[2] && $data[$key][8] == $numbers[3] && $data[$key][9] == $numbers[4] && $data[$key][10] == $numbers[5] && $data[$key][11] == $numbers[6] )//did they win the jackpot? { echo "You have Won!<br /><br />"; } else { echo "You did not win this time <br /><br />"; } } The above code will check the $data[$key] array and match the values against the values in the $number array. That is fine. However what if I wanted to see if only 3 values in the $numbers array matched the numbers in the $data[$key] array. How would I do that? Any help would be appreciated as I can't work out how to do this Link to comment https://forums.phpfreaks.com/topic/69197-solved-match-only-three/ Share on other sites More sharing options...
Jessica Posted September 13, 2007 Share Posted September 13, 2007 A specific three, or just if any three but only three match? Also, if it's a lottery they shouldn't have to get the numbers in order - they should just have to get all of them right, right? Does this help: <?php $numbers = array("04","13","18","21","30","46"); $bonus = "(05)"; foreach ($data as $key => $value){ $numMatched = 0; foreach($value AS $n){ if(in_array($n, $numbers)){ $numMatched++; } } print 'Matched '.$numMatched.' numbers<br> The bonus was: '.$bonus; } ?> Link to comment https://forums.phpfreaks.com/topic/69197-solved-match-only-three/#findComment-347785 Share on other sites More sharing options...
papaface Posted September 13, 2007 Author Share Posted September 13, 2007 Any three apart from the last element in the $numbers array as long as they match. Link to comment https://forums.phpfreaks.com/topic/69197-solved-match-only-three/#findComment-347786 Share on other sites More sharing options...
Jessica Posted September 13, 2007 Share Posted September 13, 2007 See above...there is some code that should help you with it. Link to comment https://forums.phpfreaks.com/topic/69197-solved-match-only-three/#findComment-347788 Share on other sites More sharing options...
papaface Posted September 13, 2007 Author Share Posted September 13, 2007 Thanks. Works great Link to comment https://forums.phpfreaks.com/topic/69197-solved-match-only-three/#findComment-347796 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.