直接上代码:

             $time=array();
$currentTime = time();
$cyear = floor(date("Y",$currentTime));
$cMonth = floor(date("m",$currentTime));
for($i=0;$i<12;$i++){
$nMonth = $cMonth-$i;
$cyear = $nMonth == 0 ? ($cyear-1) : $cyear;
$nMonth = $nMonth <= 0 ? 12+$nMonth : $nMonth;
$time[]['time']=$cyear.$nMonth;
}

结果:

 array(12) {
[0] => array(1) {
["time"] => string(5) "20194"
}
[1] => array(1) {
["time"] => string(5) "20193"
}
[2] => array(1) {
["time"] => string(5) "20192"
}
[3] => array(1) {
["time"] => string(5) "20191"
}
[4] => array(1) {
["time"] => string(6) "201812"
}
[5] => array(1) {
["time"] => string(6) "201811"
}
[6] => array(1) {
["time"] => string(6) "201810"
}
[7] => array(1) {
["time"] => string(5) "20189"
}
[8] => array(1) {
["time"] => string(5) "20188"
}
[9] => array(1) {
["time"] => string(5) "20187"
}
[10] => array(1) {
["time"] => string(5) "20186"
}
[11] => array(1) {
["time"] => string(5) "20185"
}
}

PHP生成当前月份包括最近12个月内的月份的更多相关文章

  1. JS生成当前月份包括最近12个月内的月份

    var last_year_month = function() { var result = []; for(var i = 0; i < 12; i++) { var d = new Dat ...

  2. PHP生成随机字符串包括大小写字母

    PHP生成随机字符串包括大小写字母,这里介绍两种方法: 第一种:利用字符串函数操作 <?php /** *@blog <www.phpddt.com> */ function cre ...

  3. easyUI日期框返回到月份,选择日期也只到月份

    easyUI日期框返回到月份,选择日期也只到月份,不是原创,引用了园友的一篇文章,自己写下来,以便不时之需,谢谢. 1 $(function () { $('#date').datebox({ onS ...

  4. MIT挑战(如何在12个月内自学完成MIT计算机科学的33门课程|内附MIT公开课程资源和学习顺序

    译者注:本文译自Scott H. Young的博客,Scott拥有超强的学习能力,曾在12个月内自学完成麻省理工学院计算机科学的33门课程.本文就是他个人对于这次MIT挑战的介绍和总结. 版权声明:本 ...

  5. Asp.Net MVC 从数据库生成代码(包括页面)

    项目需要,数据库已经设计完成,需要生成相关的数据访问代码和页面. 参考:http://www.tracefact.net/asp-net/aspnetmvc-model-part1.aspx http ...

  6. 一JavaScript获取当前月份的前12个月,获取最近的12个月二js实现获取当前月份前的12个月份,格式化后放在一个数组里

    一 ,var dataArr = []; var data = new Date(); var year = data.getFullYear(); data.setMonth(data.getMon ...

  7. HyperLedger Fabric 1.4 生产环境使用ca生成msp和tls(12)

    在上一章:Fabric kafka生产环境部署的基础上部署Fabric CA,使用Fabric CA进行生成公私钥和证书等文件,全部替换cryptogen工具,包括生成TLS相关的私钥和证书等文件.  ...

  8. 【Java】itext根据模板生成pdf(包括图片和表格)

    1.导入需要的jar包:itext-asian-5.2.0.jar itextpdf-5.5.11.jar. 2.新建word文档,创建模板,将文件另存为pdf,并用Adobe Acrobat DC打 ...

  9. C# 获得两日期之间所有月份(包括跨年)

    前台: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3. ...

随机推荐

  1. 商品规格笛卡尔积PHP

    <?php $color = array('red', 'green'); $size = array(39, 40, 41); $local = array('beijing', 'shang ...

  2. 如何新建PDF文档,新建PDF文档的方法

    新建PDF文件的话,有两种方式,一种是直接通过使用PDF编辑器http://bianji.xjpdf.com/来新建PDF文件,,还有一种就是将PDF文件转换成Word文件,然后在Word文件中添加, ...

  3. 错误: Error creating bean with name 'studentController': Unsatisfied dependency expressed through field 'studentServiceImpl';

    详细错误: 严重: Context initialization failed org.springframework.beans.factory.UnsatisfiedDependencyExcep ...

  4. android studio——替换全局的某个字符串

    android studio——替换全局的某个字符串 edit - > replace in path https://blog.csdn.net/dragon0103/article/deta ...

  5. 必须知道的Linux内核常识详解

    一.内核功能.内核发行版 1.到底什么是操作系统 (1)linux.windows.android.ucos就是操作系统: (2)操作系统本质上是一个程序,由很多个源文件构成,需要编译连接成操作系统程 ...

  6. 动态规划——Longest Valid Parentheses

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

  7. 重温TCP

    先放张TCP头图片 一.TCP三次握手目的: 1.保证源主机确定目的主机在线,并可进行通信 2.让源主机检查它是否正在监听试图去连接的端口 3.允许源主机向接收者发送他的起始序列号,使得两主机可以将数 ...

  8. Mac_配置jdk环境变量

    进入命令行 cd ~ touch .bash_profile vi .bash_profile 输入内容jdk变量配置内容: JAVA_HOME=/Library/Java/JavaVirtualMa ...

  9. [LeetCode] Swap Adjacent in LR String 交换LR字符串中的相邻项

    In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of ...

  10. Java代码导入导出 Excel 表格最简单的方法

    import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStrea ...