Home > Backend Development > PHP Problem > How to implement different random numbers in php

How to implement different random numbers in php

藏色散人
Release: 2023-03-06 14:54:02
Original
2517 people have browsed it

php method to implement different random numbers: first use the range function to generate an array from 0 to 10; then use the shuffle function to randomly shuffle the generated $num array; finally, randomly select the first 5 numbers in the array, that is Can.

How to implement different random numbers in php

Recommended: "PHP Video Tutorial"

Use PHP to generate multiple different random numbers at the same time

Example: Generate 5 different random numbers at the same time

<?php 
    $num = range(0,10);//利用range()函数产生一个0到10的数组
    shuffle($num);//利用shuffle()函数将产生的$num数组随机打乱顺序
    for ($i=0; $i < 5; $i++) {//选取数组前5个,即随机 
        echo $num[$i]."&nbsp";
    }
 ?>
Copy after login

The above is the detailed content of How to implement different random numbers in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template