Home > Backend Development > PHP Tutorial > php 抽奖小程序_PHP教程

php 抽奖小程序_PHP教程

WBOY
Release: 2016-07-13 10:37:45
Original
882 people have browsed it

这个抽奖小程序,在实际的测试环境中也可以用到,比方说测试数据的查询在in条件下,要查询随机的5个id,然后在用ab去压测    

[代码] [PHP]代码

view source print? 01 <?php 02 /** 03  * “抽奖”函数 04  * 05  * @param integer $first    起始编号 06  * @param integer $last     结束编号 07  * @param integer $total    获奖人数 08  * 09  * @return string 10  * 11 */ 12 function isWinner($first$last$total) 13 { 14     $winner array(); 15     for ($i=0;;$i++) 16     { 17         $number = mt_rand($first$last); 18         if (!in_array($number$winner)) 19             $winner[] = $number;    // 如果数组中没有该数,将其加入到数组 20         if (count($winner) == $total)   break; 21     } 22     return implode(' '$winner); 23 } 24   25 // for test 26 echo isWinner(1, 100, 5); 27 ?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/735159.htmlTechArticle这个抽奖小程序,在实际的测试环境中也可以用到,比方说测试数据的查询在in条件下,要查询随机的5个id,然后在用ab去压测 [代码] [PHP]代...
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