babyboy808
Member
Hi,
How would I go about randomizing an array in PHP?
Basically I have an array of a few elements and on each call I want to output a different element if that makes sense
Here's where I'm at:
Most of the code is ripped from different sources.
thanks in advance,
Keith
How would I go about randomizing an array in PHP?
Basically I have an array of a few elements and on each call I want to output a different element if that makes sense
Here's where I'm at:
Code:
for($i=0; $i<=$text; $i++)
{
// The word we want to replace
$bestwords = array('best');
// The new word we want in place of the old one
$newbestwords = array('ace', 'coolest', 'finest', 'incomparable');
// Randomize array
$random = array_rand($newbestwords, 2);
// Run through the text and replaces all occurrences of $oldText
$text = str_replace($bestwords , $newbestwords , $text);
// Display the new text
echo $text;
}
thanks in advance,
Keith