-7

我需要生成 000 到 999 之间的所有数字,不重复且按顺序生成。目前我正在使用代码

    for($count = 0; $count <= 999; $count++)
    {
            echo str_pad($count, 3, '0', STR_PAD_LEFT) . "<br />\r\n";
    }

但它正在按顺序生成数字。那么有人可以为我提供以非顺序顺序生成它们且不重复的代码吗

4

1 回答 1

2

You can use a shuffle function to do that. First, create an array with values {0,1,2,3,...,999} Then, use a shuffle function to shuffle the order of element in the array. Read the example code in this link: http://php.net/manual/en/function.shuffle.php

于 2013-02-03T04:59:46.203 回答