Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes PHP and the fly likes How to assign random string value to variable in PHP5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » PHP
Bookmark "How to assign random string value to variable in PHP5" Watch "How to assign random string value to variable in PHP5" New topic
Author

How to assign random string value to variable in PHP5

Ramakanta Sahoo
Ranch Hand

Joined: Aug 23, 2008
Posts: 254

Hi All,

I have something like below. want to use any of the random values each time any query happens.


when I tried to run it gave me a error like below
Parse error: syntax error, unexpected '('

I just want to rotate the usernames when ever I query for $user , can you please let me know how to achieve this.


I'm very new to PHP so please bear with my silly syntax questions


Regards, Ricky
Oracle Weblogic 10g Certified Expert TechPaste.Com
Unnar Björnsson
Ranch Hand

Joined: Apr 30, 2005
Posts: 164
If I understand you correctly you want to retrieve a random value from $abc each time an instance of the class is created, in that case you would use rand(minvalue, maxvalue) i.e:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to assign random string value to variable in PHP5