An example of PHP lottery applet code

WBOY
Release: 2016-07-25 08:58:39
Original
1104 people have browsed it
  1. /**

  2. * php lottery function
  3. *
  4. * @param integer $first starting number
  5. * @param integer $last ending number
  6. * @param integer $total number of winners
  7. *
  8. * @return string
  9. *
  10. */
  11. function isWinner($first, $last, $total)
  12. {
  13. $winner = array();
  14. for ($ i=0;;$i++)
  15. {
  16. $number = mt_rand($first, $last);
  17. if (!in_array($number, $winner))
  18. $winner[] = $number; // if in array If there is no such number, add it to the array
  19. if (count($winner) == $total) break;
  20. }
  21. return implode(' ', $winner);
  22. }

  23. / / for test

  24. echo isWinner(1, 100, 5);
  25. ?>
Copy the code

It is very simple, it is only for practice and research by beginners.



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!