What I need is, I want to save an array of different sentences and let one of them randomly display on every pageload. Would that be possible? If yes, then how?
Asked
Active
Viewed 140 times
-1
-
Put all the sentences in an array, select one at random and display it. What's the problem? – Barmar Sep 21 '14 at 07:53
-
I don't know PHP yet. – Sasha Raysky Sep 21 '14 at 07:55
-
Then use Python, Perl, Ruby, or whatever language you know. – Barmar Sep 21 '14 at 07:56
-
It's very easy to find a [solution](http://www.3till7.net/2005/06/08/random-quotes-with-php/) on the web using Google. Please invest some research effort before asking trivial questions here. – honk Sep 21 '14 at 07:59
1 Answers
1
$a = array("red","green","blue","yellow","brown");
$random = array_rand($a);
echo $a[$random] ;

Kamal Saleh
- 479
- 1
- 5
- 20
-
2`array_rand()` returns the key, not the value. You need `echo $a[$random]`. – Barmar Sep 21 '14 at 07:55
-