Hongmu Notes
Home Language Notes PHP randomly generates a number within a specified range and outputs it separated by English commas.
Language Notes PHP

PHP randomly generates a number within a specified range and outputs it separated by English commas.

PHP randomly generates a number within a specified range and outputs it separated by English commas.

Here is a simple PHP function that generates a random number within a specified range and returns a string separated by English commas:

function generateRandomNumbers($min, $max, $count) {
    $numbers = array();

    for ($i = 0; $i < $count; $i++) {
        $numbers[] = mt_rand($min, $max);
    }

    return implode(',', $numbers);
}

This function is being used. mt_rand() The function generates random numbers within a specified range and adds each random number to an array. Finally, use it. implode() The function concatenates the array elements into a single string using English commas and returns this string.

You can call this function to generate a random number as follows:

$min = 1;          // 最小值
$max = 100;        // 最大值
$count = 10;       // 生成数量

$randomNumbers = generateRandomNumbers($min, $max, $count);
echo $randomNumbers;

The above code generates 10 random numbers between 1 and 100 and outputs a string separated by English commas. You can modify this code as needed. $min$max$count Value.

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

PHP ob function record

PHP ob function record Language Notes PHP

Usage of the following three functions ob_get_contents(); ob_end_clean(); ob_start(); You can use these functions to buffer local files and execute local script code. Use ob_start() to save the output code into the buffer, and the page will not be displayed; then use ob_get_contents to get the data in the buffer. o…
👁 141
PHP preg

PHP preg Language Notes PHP

The preg_match_all function is used to perform a global regular expression match. preg_match_all() Syntax int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG…
👁 169
Detailed explanation of PHP ternary operator and if

Detailed explanation of PHP ternary operator and if Language Notes PHP

Ternary operator condition ? Result 1 : Result 2 Explanation: The position in front of the question mark is the condition for judgment. If the condition is met, the result is 1, and if it is not met, the result is 2. This article compares and explains the ternary operator and if...else... in detail. I hope it will be helpful to everyone. Today when I was revising my paper online, I encountered a statement that I couldn’t understand: $if_summary = $row['IF_SUMMARY']=…
👁 189
PHP cast type

PHP cast type Language Notes PHP PHP collection PHP and mysql

Get the data type 1. If you want to check the value and type of an expression, use var_dump(). 2. If you just want to get an easy-to-read type expression for debugging, use gettype(). 3. To check a certain type, do not use gettype(), but use the is_type() function. Converting Strings to Numbers When a string is evaluated as a number, the result is determined according to the following rules...
👁 232

Recommended reading

(Adaptive mobile version) Responsive PBootCMS renovation and design company website template – Download source code for full-home customization websites: 0254

(Adaptive mobile version) Responsive PBootCMS renovation and design company website template – Download source code for full-home customization websites: 0254 Practical Collection pbootcms Template

An adaptive, responsive website template for PbootCMS, designed for home renovation and interior design companies. It features a modern, premium design style ideal for showcasing project examples and design concepts for home renovation and whole-house customization businesses. This template helps renovation companies attract homeowners online and enhance their brand reputation. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles...
👁 56
(Adaptive mobile version) Responsive album image website template – Download source code for image wallpaper websites – 0939

(Adaptive mobile version) Responsive album image website template – Download source code for image wallpaper websites – 0939 Practical Collection pbootcms Template

A responsive PbootCMS website template designed for album-style images and wallpaper displays, compatible with both PC and WAP devices. Its visual art-oriented design makes it ideal for photographers and designers to showcase their portfolios and photographic works. This template helps visual creatives present their work online, attracting clients and followers. Template Demo | Installation Instructions | Website Admin Panel: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5....
👁 52
Responsive stone carving sculpture website template 0462

Responsive stone carving sculpture website template 0462 Practical Collection Yiyou template

This EyouCMS responsive template is ideal for the stone carving, sculpture, and statue industries. Its classical artistic design is perfect for showcasing stone carving works, sculptural products, artistic designs, and brand stories. It helps stone carving brands showcase their craftsmanship online and attract collectors as well as landscape architecture clients. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS...
👁 41
Responsive Tea Ceremony Company Website Template – 1180

Responsive Tea Ceremony Company Website Template – 1180 Practical Collection Yiyou template

A responsive website template designed specifically for tea production companies, tea culture promotion organizations, and tea utensil retailers. Featuring a classical and elegant design, this template perfectly complements the cultural heritage of tea products. It is ideal for tea companies, tea wholesalers, or tea culture enthusiasts to create a professional brand website to showcase their product ranges and tea ceremony aesthetics. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles...
👁 51
EmpireCMS – Using PHP to call navigation tags (Simple & Clear Version)

EmpireCMS – Using PHP to call navigation tags (Simple & Clear Version) Language Notes PHP

I originally used PHP to generate a navigation menu, but since many of you don't have PHP experience, I received numerous feedback requests. As a result, I've revised the code – this time, I've separated the PHP logic from the HTML markup. After this separation, the code is now much clearer. Compared to my previous article titled "Advanced PHP Code for Generating Empire Navigation Menus," you'll find that even those with just a basic understanding of HTML can easily comprehend and apply these changes! Here is the code: 🔒...
👁 397
(Adaptive mobile version) Responsive SEO-optimized website development and ranking enhancement service – Company website using PbootCMS template; Download source code for company website development services – 0255

(Adaptive mobile version) Responsive SEO-optimized website development and ranking enhancement service – Company website using PbootCMS template; Download source code for company website development services – 0255 Practical Collection pbootcms Template

This set includes PbootCMS website templates designed by a professional company specializing in adaptive mobile-friendly responsive SEO optimization and website development and ranking services. The tech-driven marketing style effectively showcases SEO services, website development projects, and optimization results. It helps digital marketing agencies demonstrate their expertise online and attract business clients seeking promotional solutions. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www...
👁 44