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

How to implement different random numbers in php

藏色散人
藏色散人Original
2020-10-09 10:10:512506browse

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";
    }
 ?>

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!

Statement:
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