概率横幅旋转广告
我有带有浏览量的横幅广告,例如 CPM 系统。 例如:
i have 3 banner:
banner1 with 20.000 nr of views
banner2 with 10.000 nr of views
banner3 with 5.000 nr of views
在我的网站上,横幅必须出现在这个位置(当页面重新加载时):
banner1banner2banner1banner2banner3
如果浏览量较高,则幽灵出现的概率较高,
我如何在php中执行此操作?
I have banners advertising with number of views, like CPM system.
And for example :
i have 3 banner:
banner1 with 20.000 nr of views
banner2 with 10.000 nr of views
banner3 with 5.000 nr of views
and on my website the banner must to appear in this position (when the page is reloaded) :
banner1 banner2 banner1 banner2 banner3
if the number of views is higher then the probability of apparition is higher
how can i do this in php?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,你的系统只是......愚蠢。它使具有大量视图的横幅永久存在,而新创建的具有 0 或很少视图的横幅永远不会有机会被选中,因此永远不会真正被看到...
话虽这么说,如果您有一个数组看起来像这样:
您可以使用这样的函数来重点选择一个横幅:
用法(测试一下@ CodePad .org 或 @ IDEOne):
来自 100 次执行的示例:
First of all, your system is just... stupid. It perpetuates banners with lots of views while newly created banners with 0 or few views will never get a chance to be picked and thus will never be actually seen...
That being said, if you have an array that looks like this:
You can use a function like this one to weightily pick one banner:
Usage (test it @ CodePad.org or @ IDEOne):
Sample from 100 executions:
这是一种 php 方法,
我想象你的数组看起来像这样...
这个函数基本上循环遍历横幅,无论横幅有多少视图,其数组索引的许多项目都会添加到数组中。然后随机选择一个。浏览次数越多的项目被选择的机会就越大。
一个简单的 mysql 选项是:
具有更多浏览次数的横幅将有更高的机会成为顶部结果
Here's a php way to do it
I'm imagining your array will look something like this...
This function basically loops through the banners and however many views a banner has, that many items of its array index are added to an array. Then a random one is chosen. Items with more views have a better chance of being chosen.
A simple mysql option is:
banners with more views will have a higher chance of being the top result