Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie! need help with number checker!

Status
Not open for further replies.

NickyJay

Programmer
Sep 1, 2003
217
GB
Hi all,

wondering how best to do this - jsut a simple app i want to build that stores syndicate members lottery numbers and is updated after each play (this part im ok with) What i want to do is try and indicate how many numbers stored match the numbers played. I'm just starting with php and dont know any of the functions but what better way to learn! I currently have the numbers stored in a mysql db, in 2 formats - one is a field containing all the players numbers, comma seperated, the other way is one number per column - wasnt sure how best to structure for the matching!

Any advice or pointers are gratefully received!

Thanks :0)
 
Hi

The suitable solution may depend on your country's lottery rules. Could you enumerate them in a few words ? ( The count of played numbers is fixed or variable; has the number's order also match; is there a joker number too; is there criteria which eliminates a set of played numbers; anything else ? )

Feherke.
 
Hiya, many thanks for looking through my post!

The rules are basically player picks 6 numbers from 1-49, 5 balls are drawn plus 1 bonus ball, any matching more than 4 of players numbers - ie, 4 numbers, 5 number, 5+bonus - win an amount..

Does this help at all?
 
the approach is this (I suggest):

1. store each of the syndicate numbers in an numeric array.
2. store the winning numbers in a numeric array. and store the bonus ball in a separate variable.
3. run array_diff on them
4. use in_array for the bonus ball

Code:
$syndicateNumbers = array( 3, 7, 9, 10, 12, 15);
$winningNumbers = array(3,7,15, 19, 30);
$bonus = 49;

//find number of winners
$diff = array_diff ($syndicateNumbers, $winningNumbers);
$matches = 6 - count($diff);
if (in_array($bonus, $syndicateNumbers)){
 echo "Matched $matches and the bonus";
} else {
 echo "Matched $matches";
}
 
many thanks for this! I will give it a go and post back how i get on :-D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top