Home  >  Article  >  Backend Development  >  An example of PHP lottery applet code

An example of PHP lottery applet code

WBOY
WBOYOriginal
2016-07-25 08:58:391116browse
  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.



Statement:
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