[代码] [PHP]代码
view source print?01
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
?>