duanjihe5180 2013-02-01 15:04 采纳率: 100%
浏览 36
已采纳

使用PHP每12小时在网站上交换图像的最简单方法

I haven't coded in a while and I'm trying to find the easiest solution to this problem.

I have 20+ images on the server (labelled 1.png, 2.png, 3.png, etc.) and I'm using PHP to render three of them to my website at a time.

All I want is to make it so every twelve hours a new image replaces one of the old images. So for example it starts by rendering images 1, 2 and 3 and after twelve hours it switches to 2, 3 and 4.

What's the best way to achieve this effect?

  • 写回答

9条回答 默认 最新

  • dslf46995 2013-02-01 15:28
    关注

    This can be done in simple PHP (since you mentioned PHP).

    $numOfImages = 20;
    $unit = date('j') * 2; // Day of the month, doubled to simulate chunks of 12 hours.
    if (date('G') < 12) { // Hours 0 - 23
        $unit--;
    }
    
    $image1 = $unit % $numOfImages;
    $image2 = ($unit + 1) % $numOfImages;
    $image3 = ($unit + 2) % $numOfImages;
    
    var_dump($image1);
    var_dump($image2);
    var_dump($image3);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(8条)

报告相同问题?

悬赏问题

  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?