Implement a simple random lottery applet based on PHP
A small lottery program, the overview is controllable, and a certain prize can be displayed on the front end, but it is impossible to get it in the program! After adding up all the probabilities x10, the value of each item in the new array is equal to the sum of its previous ones plus itself.
Then it immediately generates a number between 0 and the maximum number, checks which interval it belongs to through a loop, and returns the key of that interval.
The code is as follows
$prize = array( 1 => 3.5, //3.5%机率 2 => 2.5, 3 => 6, 4 => 2, 5 => 42, //42%机率 6 => 36, 7 => 2, 8 => 4, 9 => 2 ); //最后确认相加等于100 $prizeList = array( 1 => array('小仙子'), 2 => array('5Q币'), 3 => array('38888游戏币'), 4 => array('88888游戏币'), 5 => array('谢谢参与!'), 6 => array('欢迎下次再来!'), 7 => array('10Q币'), 8 => array('888银元宝(绑定)'), 9 => array('随机高级坐骑(绑定)') ); //unset($prize[7]); 直接把10Q这个奖品去掉 $times = 10; $max = 0; foreach ($prize as $k => $v) { $max = $v * $times + $max; $row['v'] = $max; $row['k'] = $k; $prizeZone[] = $row; } $max--; //临界值 $rand = mt_rand(0, $max); $zone = 1; foreach ($prizeZone as $k => $v) { if ($rand >= $v['v']) { if ($rand >= $prizeZone[$k + 1]['v']) { continue; } else { $zone = $prizeZone[$k + 1]['k']; break; } } $zone = $v['k']; break; } print_r($prizeList[$zone][0]);
That’s all I have written for you to implement a simple lottery applet based on PHP, but they are all core codes. I hope it will be helpful to everyone’s study and work.
The above introduces the implementation of a simple random lottery applet based on PHP, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

During the development or learning process of using Golang, we may encounter the error message of undefined:rand.Seed. This error usually occurs when you need to use a random number generator, because in Golang you need to set a random number seed before you can use the function in the rand package. This article will explain how to resolve this error. 1. Introduce the math/rand package. First, we need to introduce the math/rand package into the code. exist

iPhone 15 Pro vs. iPhone 14 Pro: Specs Comparison Here is a spec comparison between iPhone 15 Pro Max and iPhone 14 Pro Max: iPhone 15 Pro Max iPhone 14 Pro Max Display size 6.7 inches 6.7 inches Display technology Super Retina 2,000 nits Dimensions 6.29x3.02x0.32 inches 6.33x3.06x0.31 inches Weight 221 grams 240 grams

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

The latest iPhone Pro series is equipped with a powerful 48MP sensor that ensures highly detailed and crystal clear photos to capture every precious moment. However, one potential drawback is the size of full-resolution images, especially those in ProRAW format. Although the maximum storage space offered by the iPhone is 512GB, capturing a lot of ProRAW images (about 75MP each) and video (440MB per minute, 60FPS) can quickly eat up your storage space. This can cause problems if you plan to use your iPhone as your main camera for large projects or travel. But wouldn't it be great if you could take those high-resolution 48MP photos without worrying about storage limitations? it's quick

Title: Example of using the Array.Sort function to sort an array in C# Text: In C#, array is a commonly used data structure, and it is often necessary to sort the array. C# provides the Array class, which has the Sort method to conveniently sort arrays. This article will demonstrate how to use the Array.Sort function in C# to sort an array and provide specific code examples. First, we need to understand the basic usage of the Array.Sort function. Array.So

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

Although Apple will launch the iPhone's video playback time to let users know that the iPhone battery is almost available. But normal users don't use their iPhone to view videos all day long. 7 iPhones tested for endurance in daily applications. Includes 7 models including iPhone15ProMax, iPhone15Pro, iPhone15Plus, iPhone15, iPhone14ProMax, iPhone14 and iPhone13ProMax. Running through some daily applications, such as Spotify, Zoom, Tiktok, Headspace, think about Apps, games, etc., we can see the battery life of different iPhones. this
