What are some best practices for creating a banner rotation script in PHP?

When creating a banner rotation script in PHP, it is important to randomize the selection of banners to ensure equal distribution and avoid bias towards certain banners. One way to achieve this is by using an array to store the banner image paths and then randomly selecting one each time the script is executed.

<?php

// Array of banner image paths
$banners = [
    'banner1.jpg',
    'banner2.jpg',
    'banner3.jpg',
    'banner4.jpg',
];

// Randomly select a banner from the array
$randomBanner = $banners[array_rand($banners)];

// Display the selected banner
echo '<img src="' . $randomBanner . '" alt="Banner Image">';
?>