-
-
/** - * php 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 in array If there is no such number, add it to the array
- if (count($winner) == $total) break;
- }
- return implode(' ', $winner);
- }
/ / for test
- echo isWinner(1, 100, 5);
- ?>
-
-
Copy the code
It is very simple, it is only for practice and research by beginners.
|