...

View Full Version : How do I select a random array element ?



jeddi
01-16-2010, 07:51 PM
I would like to take a list of phrases and
pick one out at random.


$keywords = array( keyword one,keyword phrase two,and another,one,maybe one,more as well)


Maybe I need to write:


$keywords = array( 'keyword one','keyword phrase two','and another','one','maybe one','more as well')


How would I randomly pick one of these ?

Puffin the Erb
01-16-2010, 07:58 PM
$keywords = array( 'keyword one','keyword phrase two','and another','one','maybe one','more as well');

shuffle($keywords);

echo $keywords[0];

jeddi
01-16-2010, 08:02 PM
Oh - that's easy then :)

Thanks :thumbsup:

Puffin the Erb
01-16-2010, 08:13 PM
np, PHP has a function for everything - why reinvent the wheel ;-)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum