PHP - Don't repeat random selection

Duawldigalita

New Member
I have a small PHP script that is selecting a random sentence from an array\[code\]$prefixes = array('sentence 1', 'sentence 2');echo $prefixes[rand(0,count($prefixes)-1)];\[/code\]How can I make it not pick the same sentence twice in a row?Edit: Sorry, yeah there will be around 100 sentences and they can be used over and over again just not twice in a row. It's an on click event that re-loads the sentence to the page with AJAX and if it picks the same sentence twice in a row it looks like clicking the button hasn't done anything as there is no page refresh. ThanksEdit 2: Basically it's a DIV with a sentence in, when you click a button it loads a new sentence into the DIV via AJAX and replaces the old sentence with the new one. Sometimes it was loading the same sentence twice in a row which gave the effect the button wasn't doing anything
 
Back
Top