<?php
$random1 = '<p>Quotes van de fans:</p><h2>Why join the navy<BR />if you can be a pirate.</h2><h3>Steve jobs</h3>';
$random2 = '<p>Quotes van de fans:</p><h2>Lorem2</h2><h3>Steve jobs</h3>';
$random3 = '<p>Quotes van de fans:</p><h2>Lorem3</h2><h3>Steve jobs</h3>';
echo(rand($random1, $random2, $random3));
?>
So I’ve written the code above. I want my code to randomize the quote that appears. Would there be an user-friendly way of implementing this in a website?
I’m building a website in WordPress and I was wondering if WordPress (or PHP) had an easier method of randomizing output.
Alternatively, you could define an array which contains HTML strings and then use an
array_rand()
function to get a random entry/element. Example:I would use something like this:
?>
You could also do this clean and simply: