dongyue0225 2014-04-26 08:01
浏览 18

仅当日期在某个点之后时,Foreach循环

I want to go to end of loop only if date is past 2013-09, so not

2013-08
2013-09

but

2013-10
2013-11
2013-11
2014-01

My loop:

foreach ($data as $key=>$row) {
    $date = explode('-', explode(' ', trim(explode(' ', getTime($row))[0]))[0]);
    $year = intval($date[0], 10);
    $month = intval($date[1], 10);

    if (!($year >= 2013) || !($year == 2013 && $month >= 10)) {
        continue;
    }

    echo "{$year}-{$month}
";
}

It gives me dates from 2013-10-01 to 2013-12-31 but nothing past that date, why?

Input data in array goes like this (if it's hard to read from code, here you have vardump):

array (size=3)
  0 => string '2012' (length=4)
  1 => string '12' (length=2)
  2 => string '14' (length=2)
array (size=3)
  0 => string '2012' (length=4)
  1 => string '12' (length=2)
  2 => string '15' (length=2)
  • 写回答

1条回答 默认 最新

  • duanbing6955 2014-04-26 08:26
    关注

    Got it working:

    if (!($year >= 2013)) {
        continue;
    }
    
    if ($year == 2013) {
        if (!($month >= 10)) {
            continue;
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教