• 输出每月的第一天和最后一天


    <?php
    
    function getDateType($count, $type, $sort = 2)
    {
    $time = [];
    $cyear = floor(date("Y", time()));
    $cMonth = floor(date("m", time()));
    
    for ($i = 0; $i < $count; $i++) {
    
    $nMonth = $cMonth - $i;
    $cyear = $nMonth == 0 ? ($cyear - 1) : $cyear;
    $nMonth = $nMonth <= 0 ? 12 + $nMonth : $nMonth;
    $date = $cyear . "-" . $nMonth . "-1";
    
    if ($type == 1) {
    
    $firstday = date('Y-m-01', strtotime($date));
    $lastday = date('Y-m-t', strtotime($date));
    
    @$time[$i][0] .= $firstday;
    @$time[$i][1] .= $lastday;
    } elseif ($type == 2) {
    
    $firstday = date('Y年m月', strtotime($date));
    @$time[$i] .= $firstday;
    }
    }
    
    return $sort != 2 ? $time : array_reverse($time);
    }
    
    $a = getDateType(12, 1);
    
    var_dump($a);
    
     
    
    //输出
    array (size=12)
    0 => 
    array (size=2)
    0 => string '2018-07-01' (length=10)
    1 => string '2018-07-31' (length=10)
    1 => 
    array (size=2)
    0 => string '2018-08-01' (length=10)
    1 => string '2018-08-31' (length=10)
    2 => 
    array (size=2)
    0 => string '2018-09-01' (length=10)
    1 => string '2018-09-30' (length=10)
    3 => 
    array (size=2)
    0 => string '2018-10-01' (length=10)
    1 => string '2018-10-31' (length=10)
    4 => 
    array (size=2)
    0 => string '2018-11-01' (length=10)
    1 => string '2018-11-30' (length=10)
    5 => 
    array (size=2)
    0 => string '2018-12-01' (length=10)
    1 => string '2018-12-31' (length=10)
    6 => 
    array (size=2)
    0 => string '2019-01-01' (length=10)
    1 => string '2019-01-31' (length=10)
    7 => 
    array (size=2)
    0 => string '2019-02-01' (length=10)
    1 => string '2019-02-28' (length=10)
    8 => 
    array (size=2)
    0 => string '2019-03-01' (length=10)
    1 => string '2019-03-31' (length=10)
    9 => 
    array (size=2)
    0 => string '2019-04-01' (length=10)
    1 => string '2019-04-30' (length=10)
    10 => 
    array (size=2)
    0 => string '2019-05-01' (length=10)
    1 => string '2019-05-31' (length=10)
    11 => 
    array (size=2)
    0 => string '2019-06-01' (length=10)
    1 => string '2019-06-30' (length=10)
    

      

  • 相关阅读:
    为什么需要防火墙?
    比较流行的前端框架
    java基础面试题
    单列模式
    简单而且好用的随机验证码
    java中的九大隐藏变量.
    搭建Disuz论坛社区
    BZOJ 1006 [HNOI2008]神奇的国度
    COJ 0252 HDNOIP201304阻断传染
    BZOJ 1005 [HNOI2008]明明的烦恼
  • 原文地址:https://www.cnblogs.com/qczy/p/10958495.html
Copyright © 2020-2023  润新知