Search code examples
phpshufflegenerate-series

How to shuffle this generated (000 -999) value


Please fix it..

I want to shuffle the value that i will get from the following code.

<?php
for ( $i = 000; $i < 1000; $i++){
echo str_pad($i, 3, '0', STR_PAD_LEFT) . "<br />\r\n";
}
?>

Please help me by fixing the above code

Thank you


Solution

  • Try this:

    $ar=range(0, 1000);
    shuffle($ar);
    foreach ($ar as $key => $value) {
      echo str_pad($value, 3, '0', STR_PAD_LEFT) . "<br />\r\n";
    }