How to realize the Code of php Lucky turntable
This article mainly explains "how to realize the code of php lucky turntable". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "php lucky turntable code how to achieve" it!
Php lucky turntable implementation method: 1, create a PHP example file; 2, through the code "function get_gift () {...}" to achieve the big turntable lottery algorithm.
This article operating environment: Windows7 system, PHP7.4 version, Dell G3 computer.
How to realize the code of php lucky turntable?
PHP realizes the lottery algorithm of large turntable
Code:
Function get_gift () {/ / assemble award array / / award id, prize Probabilities $prize_arr = array ('0' = > array ('id'= > 1graded priority = >' tablet', 'vault = > 0),' 1' = > array ('id'= > 2reign primer = >' digital camera', 'vault = > 1),' 2' = > array ('id'= > 3prizekeeper = >' speaker device', 'vault = > 1) '3' = > array (' id'= > 4 camera prizecards = > 4G flash drive', 'vault = > 1),' 4' = > array ('id'= > 5 camera prizecards = >' 10Q coins', 'vicious = > 1),' 5' = > array ('id'= > 6 prizecards = >' empty prizes', 'vests = > 6),) Foreach ($prize_arr as $key = > $val) {$arr [$val ['id']] = $val [' v']; / probability array} $rid = get_rand ($arr); / / id $res ['yes'] = $prize_arr [$rid-1] [' prize']; / / winning award unset ($prize_arr [$rid-1]) / / remove the winning prize from the array, leaving the unwon prize shuffle ($prize_arr); / / disrupt the array order for ($item0) / proCur) {$randNum = mt_rand (1, $proSum); / / return a random integer if ($randNum)