The previous implementation just picked one ad and tried to display it, regardless if it should be displayed based on the condition. The change will show the first random ad that fulfills the display conditions.
$ads[] = $ad;
}
- if (ENABLE_AD_ROTATION && count($ads) > 1) {
- $ads = [
- $ads[mt_rand(0, count($ads) - 1)]
- ];
- }
+ if (ENABLE_AD_ROTATION) shuffle($ads);
$output = '';
foreach ($ads as $ad) {
}
$output .= '<div>' . $ad->ad . '</div>';
+ if (ENABLE_AD_ROTATION) break;
}
if (!empty($output)) {