Efficient banner rotation with PHP

Posted by reggie on Stack Overflow See other posts from Stack Overflow or by reggie
Published on 2012-10-28T10:38:13Z Indexed on 2012/10/28 11:01 UTC
Read the original article Hit count: 326

Filed under:
|
|
|

I rotate a banner on my site by selecting it randomly from an array of banners.

Sample code as demonstration:

<?php
$banners = array(
'<iframe>...</iframe>',
'<a href="#"><img src="#.jpg" alt="" /></a>',
//and so on
);
echo $banners(rand(0, count($banners)));
?>

The array of banners has become quite big. I am concerned with the amount of memory that this array adds to the execution of my page. But I can't figure out a better way of showing a random banner without loading all the banners into memory...

© Stack Overflow or respective owner

Related posts about php

Related posts about random