Jump to content

Archived

This topic is now archived and is closed to further replies.

Refused

Randomization

Recommended Posts

Just a quick query, while i learn about databases for PHP i am making a small script with the PHP i do know.

What i have tried but just cant figure it out though (i need for the script im making) is a randomization. Basiclly i want is to have a randomized word to output on the page onced a user has filled in some info and pressed the submit button.
Now i know how to do it all except for how to make a random word, i would like to add a fair amount of words in it.

So would anyone either post, or explain how to make a random word appear.

Thanks.

Share this post


Link to post
Share on other sites
[code]
$words = array("zero","one","two","three","four","five","six","seven","eight","nine");
echo $words[rand(0,(count($words)-1))];
[/code]

store some words on an array, then just generate a random index
from zero to max index of array ( (count($words)-1)) )

Share this post


Link to post
Share on other sites
Thankyou for your help.
That is very close how i had been doing it, i knew an array needed to be used to store the words but i couldent figure out that second part.

Thanks.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.