$apple="";
$banana="";
$apple="Red";
$banana="Blue";
$random(rand($apple, $banana);
echo $random;
How can I select a random string (fast) via PHP?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Issue with your code
The PHP
rand()function takes two numbers as input to form the range to pick a random number from. You cannot feed it strings.See the PHP manual page for
rand().Solutions
You can use
array_rand():Another option is to use
shuffle().