Create a Simple Banner Rotator with PHP in a Minute

PHP shuffle randomizes (shuffles) the order of the elements in an array. You may use this function to create a simple banner rotator.

Define your banners

Create $banners array with the links of each banner. Then shuffle this array.

<?php
$banner1 = '<a href="BANNER1_URL" target="_blank"><img src="BANNER1_IMG_SRC" alt="BANNER1_ALT" title="BANNER1_TITLE"></a>';
$banner2 = '<a href="BANNER2_URL" target="_blank"><img src="BANNER2_IMG_SRC" alt="BANNER2_ALT" title="BANNER2_TITLE"></a>';
$banner3 = '<a href="BANNER3_URL" target="_blank"><img src="BANNER3_IMG_SRC" alt="BANNER3_ALT" title="BANNER3_TITLE"></a>';
$banner4 = '<a href="BANNER4_URL" target="_blank"><img src="BANNER4_IMG_SRC" alt="BANNER4_ALT" title="BANNER4_TITLE"></a>';
$banners = array($banner1, $banner2, $banner3, $banner4);
shuffle($banners);
?>

Display random banner

Just put this code, where you want to display your random banner

<div>
        <?php echo $banners[0]; ?>
</div>

References

From PHP manual

Your comments are welcome!