php - Shuffle an array multiple times without repeating values at any ID -
i trying figure out way shuffle array , unique result multiple times. i've been googleing , searching sight yet find answer.
for example; let have array $foo = [1, 2, 3, ... 99, 100] (array length vary), want shuffle multiple times (say, 5 times) value not repeated @ id.
as example, imagine each line below represents new shuffle , we're taking value of $foo[0] (all ids should follow same logic).
this good:
$foo[0] = 1 $foo[0]= 4 $foo[0]= 63 $foo[0]= 27 $foo[0]= 90 this bad (because 5 repeated):
$foo[0]= 1 $foo[0]= 5 $foo[0]= 54 $foo[0]= 5 $foo[0]= 15 what method can use achieve this?
thanks
can try ? or want repeat process 5 times ?
<?php // array $array = array_fill(1, 10, true); echo print_r(array_rand($array, 5), true); ?>
Comments
Post a Comment