Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004

    Unanswered: Comparing Values

    Sorry for the poor title,

    I am making a keno script. I am having trouble selecting the numbers which the user has got correct. So the user has selected 10 numbers out of 80 and then clicked 'BET'. I have generated 10 WINING random numbers by simply doing:

    PHP Code:
    $win1 rand(1,80);
    $win2 rand(1,80); 
    Perhaps this should be different but what I need to achieve is to take the inputted values which are simply posted variables and compare them with the generated numbers. How?

    Thanks in advance,


  2. #2
    Join Date
    Apr 2005
    Baltimore, MD
    The == operator is used for comparison. For arrays though, there are some cool functions you can use...

    If you pass the guessed numbers to your script as an array, you could do something like this:
    PHP Code:
    // http://../winners.php?guess[]=23&guess[]=38.......

    $winners = array();

    //generate 10 unique numbers
    while (count($winners) < 10) {
    $winners[] = rand(1,80);
    $winners array_unique($winners);

    //grab the guessed numbers
    $guessed $_POST['guess'];

    //see which guessed numbers are in our "winning numbers" array
    $matched array_intersect($guessed$winners);

    //output the number correct and which they were
    echo 'You got the following ' count($matched) . ' numbers correct: ';
    implode(", "$matched); 

  3. #3
    Join Date
    Aug 2004
    Thanks this worked perfectly!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts