- /**
- * “抽奖”函数
- *
- * @param integer $first 起始编号
- * @param integer $last 结束编号
- * @param integer $total 获奖人数
- *
- * @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 (count($winner) == $total) break;
- }
- return implode(' ', $winner);
- }
- // for test
- echo isWinner(1, 100, 5);
- ?>
复制代码
|