php - How to randomize an array without duplicating an integer -
for example if have this:
<?php $b = array(100); ($i = 1; $i <= 100; $i++) { $b[$i]=$i; } ?>
how randomize numbers without duplicating them?
your approach work if shuffle array:
for ($i = 1; $i <= 100; $i++) { //$b = array(100); //why here? $b[$i] = $i; } shuffle($b);
however it's simpler:
$b = range(1, 100); shuffle($b);
Comments
Post a Comment