按顺序打印数组的每一项 - 每页刷新一个

发布于 2024-09-13 14:06:41 字数 305 浏览 2 评论 0原文

就像随机图像生成器(例如: http://www.dustindiaz.com /a-simple-php-image-rotator/),仅按顺序排列。我正在运行横幅广告,客户希望它们按每个页面加载的顺序运行 1、2、3、4、5。所以他们只是循环赛。 5 页面加载,然后循环再次开始。

有什么想法吗?我用谷歌搜索了一段时间,但没有找到任何东西。

任何帮助都会很棒,非常感谢!

Like a random image generator (ex: http://www.dustindiaz.com/a-simple-php-image-rotator/), only in a sequential order. Im running banner ads, and the client would like them run 1,2,3,4,5 in order per page load. So they just go round robin. 5 page loads, then the cycle start again.

Any ideas? I've googled for a while, and i'm not finding anything.

any help would be great, thanks much!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾城花音 2024-09-20 14:06:41
<?php

// start session
session_start();
$ads = array ('Ad1', 'Ad2', 'Ad3', 'Ad4', 'Ad5');

// rotate
$id = ++$_SESSION['ad_id'] % count($ads);
$_SESSION['ad_id'] = $id;

// display ad
echo $ads[$id];

当然,您需要实际的 HTML 代码,而不是 Ad1Ad2 等。

如果您不想引起注意,可以在 session_start()

if (!isset($_SESSION['ad_id'])) $_SESSION['ad_id'] = 0;
<?php

// start session
session_start();
$ads = array ('Ad1', 'Ad2', 'Ad3', 'Ad4', 'Ad5');

// rotate
$id = ++$_SESSION['ad_id'] % count($ads);
$_SESSION['ad_id'] = $id;

// display ad
echo $ads[$id];

Of course you'd need the actual HTML code instead of Ad1, Ad2, etc.

If you don't want notices the following piece of code can be added after session_start()

if (!isset($_SESSION['ad_id'])) $_SESSION['ad_id'] = 0;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文