- /**
- * "Lottery" function
- *
- * @param integer $first starting number
- * @param integer $last ending number
- * @param integer $total number of winners
- *
- * @return string
- *
- */
- function isWinner($first, $last, $total)
- {
- $winner = array();
- for ($i=0;;$ i++)
- {
- $number = mt_rand($first, $last);
- if (!in_array($number, $winner))
- $winner[] = $number; // If the number is not in the array, replace it Add to array
- if (count($winner) == $total) break;
- }
- return implode(' ', $winner);
- }
- // for test
- echo isWinner(1, 100, 5);
- ?>
Copy code
|