Let’s say I had three variables:-
$first = "Hello";
$second = "Evening";
$third = "Goodnight!";
How would I echo a random one onto the page, as I would like to have this module in my website sidebar that would change on every refresh, randomly?
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.
Place them into an array and choose from it randomly with
rand(). The numeric bounds passed torand()are zero for the lower, as the first element in the array, and one less than the number of elements in the array.Example:
Or much more simply, by calling
array_rand($array)and passing the result back as an array key: