The example in this article describes how php obtains N non-repeating random numbers within a certain range. . Share it with everyone for your reference, the details are as follows:
//range 是将1000到9999 列成一个数组 $numbers = range (1000,9999); //shuffle 将数组顺序随即打乱 shuffle ($numbers); //array_slice 取该数组中的某一段 $result = array_slice($numbers,0,3); print_r($result);
The running result is:
Array ( [0] => 9767 [1] => 2344 [2] => 7783 )
Supplement: The editor here recommends a PHP formatting and beautifying typesetting tool on this website to help you code typesetting in future PHP programming:
php code online formatting and beautification tool:
http://tools.jb51.net/code/phpformat
In addition, since php belongs to the C language style, the following tool can also format php code:
C language style/HTML/CSS/json code formatting and beautification tool:
http://tools.jb51.net/code/ccode_html_css_json
Readers who are interested in more PHP-related content can check out the special topics on this site: "Summary of PHP mathematical operation skills", "Summary of PHP operating office document skills (including word, excel, access, ppt)", "PHP array ( Array) operating skills collection", "php sorting algorithm summary", "php common traversal algorithms and techniques summary", "php data structure and algorithm tutorial", "php programming algorithm summary", "php regular expression usage summary", "Summary of PHP operations and operator usage", "Summary of PHP string usage" and "Summary of common PHP database operation skills"
I hope this article will be helpful to everyone in PHP programming.