PHP實現(xiàn)活動人選抽獎功能
更新時間:2017年04月19日 08:44:10 作者:Qimi_
這篇文章主要介紹了PHP實現(xiàn)活動人選抽獎功能,隨機抽取指定人數(shù),依次列舉被抽中的人名,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文介紹情景為活動人選抽獎,通過簡單隨機抽取指定人數(shù),依次列舉被抽中的人名。示例代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>活動人選</title>
</head>
<body>
<?php
$lotterPeopleArr = array();
$num = 8;
for($i=0;$i<$num;$i++){
$lotterPeople = GetRandStr(1);
while(in_array($lotterPeople, $lotterPeopleArr)){
$lotterPeople = GetRandStr(1);
}
$lotterPeopleArr[$i] = $lotterPeople;
echo "抽中人:". $lotterPeopleArr[$i].'<br/>';
}
// echo '抽中人:'. $lotterPeople;
/**
* 生成隨機數(shù)
* $type int 默認(字母&&數(shù)字) 1 純字母 2.純數(shù)字 3.英文單詞
*/
function GetRandStr($len='4',$type='3')
{
switch($type)
{
case '1';
$chars = array(
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z"
);
break;
case '2';
$chars = array(
"0", "1", "2",
"3", "4", "5", "6", "7", "8", "9"
);
break;
case '3';
$chars = array(
"小華","小冠","小王","小吳","小朱","小何","小陳","小熊","小斌","小李","小春","小超","小張","小郭","小柯","小梁","小理","小龔","小杰","小余","小洪","小鄭","小志","小潘",
);
break;
default;
$chars = array(
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",
"3", "4", "5", "6", "7", "8", "9"
);
break;
}
$charsLen = count($chars) - 1;
shuffle($chars);
$output = "";
for ($i=0; $i<$len; $i++)
{
$output .= $chars[mt_rand(0, $charsLen)];
}
return $output;
}
?>
</body>
</html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
ThinkPHP5.1框架頁面跳轉(zhuǎn)及修改跳轉(zhuǎn)頁面模版示例
這篇文章主要介紹了ThinkPHP5.1框架頁面跳轉(zhuǎn)及修改跳轉(zhuǎn)頁面模版,結(jié)合實例形式分析了thinkPHP5.1框架進行頁面跳轉(zhuǎn)及修改跳轉(zhuǎn)模板相關(guān)操作技巧,需要的朋友可以參考下2019-05-05
Zend Framework教程之Zend_Controller_Plugin插件用法詳解
這篇文章主要介紹了Zend Framework教程之Zend_Controller_Plugin插件用法,結(jié)合實例形式詳細分析了Zend_Controller_Plugin插件的原理,使用方法與相關(guān)注意事項,需要的朋友可以參考下2016-03-03
簡單的php+mysql聊天室實現(xiàn)方法(附源碼)
這篇文章主要介紹了簡單的php+mysql聊天室實現(xiàn)方法,詳細介紹了數(shù)據(jù)庫,框架頁面,登錄及信息的發(fā)布、展示功能實現(xiàn)技巧,并附帶了完整源碼供讀者下載參考,需要的朋友可以參考下2016-01-01

