donglu7286 2012-06-11 23:55
浏览 11
已采纳

将时间戳月份/年列为PHP中的博客存档

Assuming I have multiple timestamps of multiple years and months in an array of timestamps (eg 123456, 111222333, 2112321321, 232234422, 1111343222, 231111211, etc), I want to sort them into this format:

2012
    06
    09

2004
    03
    08

2003
    01
    02

Is there any way of doing this? I am using PHP

  • 写回答

2条回答 默认 最新

  • douwei8672 2012-06-13 01:10
    关注

    I've found a solution:

    foreach($timestamps as $time){
        $year = date('Y', $time);
        $month = date('m', $time);
        if(!$ts_arr[$year]){
            $ts_arr[$year] = array();
        }
        array_push($ts_arr[$year], $month);
        $ts_arr[$year] = array_unique($ts_arr[$year]);
    }
    

    It's not perfect, but it works!

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

报告相同问题?

悬赏问题

  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动