display random background image or effect using php

sometimes we need to get random background image or effects which can be easily obtain using php.

below is a small demonstration how to get the random values using php..

$input = array(“jswing”,”easeInQuad”,”easeOutQuad”,”easeInOutQuad”,

“easeInCubic”,”easeOutCubic”,”easeInOutCubic”,

“easeInQuart”,”easeOutQuart”,”easeInOutQuart”,”easeInSine”,

“easeOutSine”,”easeInOutSine”,”easeInExpo”,”easeOutExpo”,

“easeInOutExpo”,”easeInQuint”,”easeOutQuint”,”easeInOutQuint”,

“easeInCirc”,”easeOutCirc”,”easeInOutCirc”,”easeInElastic”,

“easeOutElastic”,”easeInOutElastic”,”easeInBack”,”easeOutBack”,

“easeInOutBack”,”easeInBounce”,”easeOutBounce”

,”easeInOutBounce”);
$rand_keys = array_rand($input);

echo $input[$rand_keys];

if you need 2 random effects then it can be

$rand_keys = array_rand($input,2);

echo $input[$rand_keys[0]] . “\n”;
echo $input[$rand_keys[1]] . “\n”;

Similarly we can get random background image for a page on page load

$input = array(“bg1.jpg”,”bg2.jpg”,”bg3.jpg”,”bg4.jpg”,”bg5.jpg”);

$rand_keys = array_rand($input);

echo $input[$rand_keys];

if you need 2 random background images then it can be

$rand_keys = array_rand($input,2);

echo $input[$rand_keys[0]] . “\n”;
echo $input[$rand_keys[1]] . “\n”;

author:san

Comments
One Response to “display random background image or effect using php”
  1. Felisa Balcorta says:

    I simply want to tell you that I’m beginner to blogging and actually savored your web site. Very likely I’m want to bookmark your site . You actually have awesome articles. Bless you for sharing your blog site.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.