my way to preload images! haha
Update Coming Soon! Check out Skem9's future roadmap
Search for in

PHP .^. Coding Tutorials | Submited Jun 30, 2012

Written by: Yohn

If you want to know how to display something at random, then heres a simple how to, to pull it off
This is supper easy, so start off with an array with what you want to be at random

$arr = array(
'hello random string 1',
'random string 2',
'another sting',
'just filling up space',
'and again to'
);

If you want to use images, put the image url where the text is at. and then to have php pull a random string out of that..
$pick = array_rand($arr);
echo $arr[$pick];

and it would display a random string within that array. If you're using images, it would look something like the following


$arr = array('http://path.to/image.gif',
'http://other.to/image.jpg',
'http://another.img/here.png'
);

$pick = array_rand($arr);
echo '<img src="'.$arr[$pick].'" alt="img" />';


hope this helps! Enjoy


No Comments Found