Generating random image
Generating/Displaying random image in PHP.
<?php /********************************* RANDOM IMAGE GENERATION <span id="more-45"></span> *********************************/ //storing images in an array $images = array(1 => "mukesh1.jpg", 2 => "mukesh2.jpg", 3 => "mukesh4.jpg", 4 => "mukesh6.jpg", 5 => "mukesh9.jpg"); //printing the array /*** print_r($images); ***/ //generating random number //we have 5 elements in the array above //so we will generate random number from 1 to 5 $num = rand(1,5); //printing the images echo "Random Image Below: "; echo "<br/>"; echo "<img src='".$images[$num]."' alt='Random Image' title='Random Image'>"; ?>
Download code (images included):-
Enjoy PHPing !!
From Mukesh Chapagain's Blog, post Generating random image
Related posts:
- PHP: Generating Multiple Random String
- Random number, string generation in PHP
- jQuery: Grey out background and preview image as popup
- Magento: Set Random Order in Collection using RAND()
- phpThumb(): The best PHP thumbnail image generator
- jQuery: Animate and Transfer effect with Image
- jQuery: Preview Image with Tooltip Effect
- jQuery: Preview Image with Zoom Effect
- Magento: Get height and width of Image
- Magento: Get width height of image using Varien_Image class
