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 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大