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 Link to comment https://forums.phpfreaks.com/topic/37863-rand/ 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(); ?> Link to comment https://forums.phpfreaks.com/topic/37863-rand/#findComment-181269 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. Link to comment https://forums.phpfreaks.com/topic/37863-rand/#findComment-181288 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. Link to comment https://forums.phpfreaks.com/topic/37863-rand/#findComment-181292 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 Link to comment https://forums.phpfreaks.com/topic/37863-rand/#findComment-181303 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 Link to comment https://forums.phpfreaks.com/topic/37863-rand/#findComment-181310 Share on other sites More sharing options...
ted_chou12 Posted February 10, 2007 Share Posted February 10, 2007 thanks, i understand Link to comment https://forums.phpfreaks.com/topic/37863-rand/#findComment-181312 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.