Jump to content


Photo

Randomization


  • Please log in to reply
2 replies to this topic

#1 Refused

Refused
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 24 May 2006 - 07:48 AM

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.
[div align="center"][/div]

#2 eves

eves
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 24 May 2006 - 02:04 PM

$words = array("zero","one","two","three","four","five","six","seven","eight","nine");
echo $words[rand(0,(count($words)-1))];

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


#3 Refused

Refused
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 24 May 2006 - 08:33 PM

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.
[div align="center"][/div]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users