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 Quote Link to comment 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; } ?> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
papaface Posted September 13, 2007 Author Share Posted September 13, 2007 Thanks. Works great Quote Link to comment 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.