...

View Full Version : how to make random echos



jl9148
01-26-2007, 07:11 PM
hi, i was wondering how i can use php to echo random phrases/quotes like

'blah blah blah'
'asldhasf kdjhfskjf hsjdhf'

and so on.

i did find something like this..
<?
//Chooses a random number
$num = Rand (1,6);
//Based on the random number, gives a quote
switch ($num)
{
case 1:
echo "Time is money";
break;
case 2:
echo "An apple a day keeps the doctor away";
break;
case 3:
echo "Elmo loves dorthy";
break;
case 4:
echo "Off to see the wizard";
break;
case 5:
echo "Tomorrow is another day";
break;
case 6:
echo "PHP is cool!";
}
?> but for some reason, taht seems like it takes up too much space and too much time

i want a very simple script that is minimal and still works

Fumigator
01-26-2007, 07:33 PM
You could build an array of strings and use that rand() function to display a random string from the array...

Eternity Angel
01-27-2007, 01:43 AM
You could build an array of strings and use that rand() function to display a random string from the array...

And here's the code, jl, since it seems like you don't know much PHP:


$meh = array("I like cheese.","...","...");
echo $meh[array_rand($meh)];

jl9148
01-27-2007, 06:22 PM
hehe thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum