使用 PHP 进行高效的横幅旋转 [英] Efficient banner rotation with PHP

查看:42
本文介绍了使用 PHP 进行高效的横幅旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过从一系列横幅中随机选择一个横幅来旋转我网站上的横幅.

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

示例代码作为演示:

<?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...

推荐答案

将横幅移动到 html 文件并将数组更改为仅包含文件名.

Move the banners to html files and change the array to contain only filenames.

然后您可以按名称包含该文件,只加载所需的横幅.

Then you can include that file by the name, only loading the banner required.

这篇关于使用 PHP 进行高效的横幅旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆