Jump to content

Randomization


Refused

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.
Link to comment
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)) )
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.