Drezard Posted February 10, 2007 Share Posted February 10, 2007 Hello, I want to use the rand() function for a variable. So like: Code: <?php number = rand(); ?> But it gives me these errors: Quote: Parse error: parse error, unexpected '=' in C:\Program Files\xampp\htdocs\test\rand.php on line 3 Whats wrong or how can i do this? - Cheers, Daniel Quote Link to comment Share on other sites More sharing options...
The_Assistant Posted February 10, 2007 Share Posted February 10, 2007 you have a lil error in there <?php number = rand(); ?> should be <?php $number = rand(); ?> Quote Link to comment Share on other sites More sharing options...
tcollie Posted February 10, 2007 Share Posted February 10, 2007 Or if you want a random number between x and y, where x is starting number and y is ending number: $number = rand(1,50); In this example x=1 and y=50. This will generate a random number between 1 & 50. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 10, 2007 Share Posted February 10, 2007 Off Topic: You can get a random number from an existing array too. Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted February 10, 2007 Share Posted February 10, 2007 Continue the Off Topic: How do you do that please? Ted Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 10, 2007 Share Posted February 10, 2007 <?php $array = array('thing1','thing2','thing3'); $value = array_rand($array); echo $array[$value]; This will get a random image from a directory using the same concept: http://snippets.tzfiles.com/snippet.php?id=14 Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted February 10, 2007 Share Posted February 10, 2007 thanks, i understand Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.