PHP实现活动人选抽奖功能


Posted in PHP onApril 19, 2017

本文介绍情景为活动人选抽奖,通过简单随机抽取指定人数,依次列举被抽中的人名。示例代码如下:

<!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;



  /**
   * 生成随机数
   * $type int 默认(字母&&数字) 1 纯字母 2.纯数字 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>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

PHP 相关文章推荐
剖析 PHP 中的输出缓冲
Dec 21 PHP
PHP包含文件函数include、include_once、require、require_once区别总结
Apr 05 PHP
PHP+javascript制作带提示的验证码源码分享
May 28 PHP
PHP实现抓取HTTPS内容
Dec 01 PHP
PHP文件缓存类示例分享
Jan 30 PHP
php字符串函数学习之strstr()
Mar 27 PHP
php三元运算符知识汇总
Jul 02 PHP
php 生成加密公钥加密私钥实例详解
Jun 16 PHP
如何通过View::first使用Laravel Blade的动态模板详解
Sep 21 PHP
PHP使用微信开发模式实现搜索已发送图文及匹配关键字回复的方法
Sep 13 PHP
PHP扩展Swoole实现实时异步任务队列示例
Apr 13 PHP
PHP中PCRE正则解析代码详解
Apr 26 PHP
thinkphp下MySQL数据库读写分离代码剖析
Apr 18 #PHP
Thinkphp通过一个入口文件如何区分移动端和PC端
Apr 18 #PHP
Yii2汉字转拼音类的实例代码
Apr 18 #PHP
php+resumablejs实现的分块上传 断点续传功能示例
Apr 18 #PHP
ZendFramework2连接数据库操作实例
Apr 18 #PHP
PHP实现的数独求解问题示例
Apr 18 #PHP
PHP使用finfo_file()函数检测上传图片类型的实现方法
Apr 18 #PHP
You might like
php巧获服务器端信息
2006/12/06 PHP
php strstr查找字符串中是否包含某些字符的查找函数
2010/06/03 PHP
phpadmin如何导入导出大数据文件及php.ini参数修改
2013/02/18 PHP
PHP PDO fetch 模式各种参数的输出结果一览
2015/01/07 PHP
JS 表单验证大全
2011/11/23 Javascript
FireBug 调试JS入门教程 如何调试JS
2013/12/23 Javascript
Array栈方法和队列方法的特点说明
2014/01/24 Javascript
利用jQuery和CSS将背景图片拉伸
2015/10/16 Javascript
Node.js的Koa框架上手及MySQL操作指南
2016/06/13 Javascript
Bootstrap基本插件学习笔记之轮播幻灯片(23)
2016/12/08 Javascript
vue如何从接口请求数据
2017/06/22 Javascript
Angular4.0动画操作实例详解
2019/05/10 Javascript
微信小程序实现手势滑动效果
2019/08/26 Javascript
微信小程序自定义联系人弹窗
2020/05/26 Javascript
vue组件开发之slider组件使用详解
2020/08/21 Javascript
python创建列表和向列表添加元素的实现方法
2017/12/25 Python
numpy.linspace函数具体使用详解
2019/05/27 Python
python绘制已知点的坐标的直线实例
2019/07/04 Python
Pandas 重塑(stack)和轴向旋转(pivot)的实现
2019/07/22 Python
python爬取百度贴吧前1000页内容(requests库面向对象思想实现)
2019/08/10 Python
Python3视频转字符动画的实例代码
2019/08/29 Python
在Django下测试与调试REST API的方法详解
2019/08/29 Python
python selenium 获取接口数据的实现
2020/12/07 Python
美国顶级品牌男士大码服装店:DXL
2017/08/30 全球购物
班组长工作职责
2013/12/25 职场文书
物业公司采购员岗位职责
2013/12/31 职场文书
家长评语大全
2014/01/22 职场文书
中学生自我评价范文
2014/02/08 职场文书
大学新生军训感言
2014/02/25 职场文书
城市创卫标语
2014/06/17 职场文书
工作作风整顿个人剖析材料
2014/10/11 职场文书
离婚撤诉申请书范本
2015/05/18 职场文书
800字作文之大雪
2019/12/04 职场文书
完美处理python与anaconda环境变量的冲突问题
2021/04/07 Python
MySQL数字类型自增的坑
2021/05/07 MySQL
面试分析分布式架构Redis热点key大Value解决方案
2022/03/13 Redis