dounie5475 2012-04-06 10:23
浏览 31
已采纳

如何使PHP功能显示基于百分比的频率? [重复]

This question already has an answer here:

here the sample case..

i want to display banner randomly by percentage based on visitor hits. for example i want to display ads 70% of visitor hits.. the problem is we don't know how many visitor is.

if it make easier we have set percentage 10%, 20%, 30% ... 100%

  • and maybe also possible if we save counter per 100 hits and reset

Thanks in advanced.

</div>
  • 写回答

3条回答 默认 最新

  • dongzaijiao4863 2012-04-06 10:26
    关注

    You don't need to know about how many visitors. The only thing you need to do is take a random number between 1 and 100, and if it is 70 or lower, it is within this 70% range.

    Eventually this will work out, and display the banner to 70% of the people:

    if (rand(1,100) <= 70) {
        display_banner();
    }
    

    If you want to keep this number, and show it to the user for all page views, then store it in a $_SESSION var of some sort, and based on that value display the banner.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突