php 实现活动人选抽奖功能代码

怪我咯
Lepaskan: 2023-03-13 15:36:01
asal
1802 orang telah melayarinya

随机抽奖软件是一款能够在任何抽奖场合使用的电脑抽奖软件,该软件一键抽奖,并采用随机算法,保证公平公正,您可以将随机抽奖软件用于单位年会、联欢晚会、电视节目、婚庆、商场、网吧等各种现场抽奖活动之中。这篇文章主要介绍了PHP实现活动人选抽奖功能,随机抽取指定人数,依次列举被抽中的人名,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

示例代码如下:

<!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].&#39;<br/>&#39;;
  }

  // echo &#39;抽中人:&#39;. $lotterPeople;



  /**
   * 生成随机数
   * $type int 默认(字母&&数字) 1 纯字母 2.纯数字 3.英文单词
   */
   function GetRandStr($len=&#39;4&#39;,$type=&#39;3&#39;)
  {


    switch($type)
    {
      case &#39;1&#39;;
      $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 &#39;2&#39;;
      $chars = array(
          "0", "1", "2",
          "3", "4", "5", "6", "7", "8", "9"
      );
      break;
      case &#39;3&#39;;
      $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>
Salin selepas log masuk

Atas ialah kandungan terperinci php 实现活动人选抽奖功能代码. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!