Randomized quote display PHP
You can use example below in many different situations, idea is to create a list of quotes in array, and using PHP array_rand(), we can pick random entries out of an array.PHP
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
<?php
//array of short quotes (taken from http://www.curatedquotes.com/)
$array_of_quotes = array(
'I don\'t want to earn my living; I want to live.',
'Life shrinks or expands in proportion to one\'s courage.',
'Life must be lived forwards, but can only be understood backwards.',
'Be the change you wish to see in the world.',
'This is your life, and it\'s ending one minute at a time.',
'Love the life you live, and live the life you love.'
);
//array_rand(array, number)
$randome_key = array_rand($array_of_quotes);
//print out a random quote
print $array_of_quotes[$randome_key];
?>