I'm hoping to create a random function that will display a random order of the items in an array each time a page is called. The problem is that as each position in this array is used, the next random call should not access it so there are no repeats of the same item.
Here is the reckless code I have crafted so far:
$list = array ("apple", "orange", "banana","plum"
$itemzero = rand(0,3);
$zerofruit = $list[$itemzero];
$itemone = rand(0,3);
$firstfruit = $list[$itemone];
$itemtwo = rand(0,3);
$secondfruit = $list[$itemtwo];
$itemthree = rand(0,3);
$thirdfruit = $list[$itemthree];
print ("$itemzero<br>$itemone<br>$itemtwo<br>$itemthree\n"
Is there a way to do this without randomly repeating items?
What if I have an array of 20 items? Can my sloppy code be simplified?
Here is the reckless code I have crafted so far:
$list = array ("apple", "orange", "banana","plum"
$itemzero = rand(0,3);
$zerofruit = $list[$itemzero];
$itemone = rand(0,3);
$firstfruit = $list[$itemone];
$itemtwo = rand(0,3);
$secondfruit = $list[$itemtwo];
$itemthree = rand(0,3);
$thirdfruit = $list[$itemthree];
print ("$itemzero<br>$itemone<br>$itemtwo<br>$itemthree\n"
Is there a way to do this without randomly repeating items?
What if I have an array of 20 items? Can my sloppy code be simplified?