【问题标题】:Warning range() : The supplied range exceeds the maximum array size: start=0 end=1508715000警告范围():提供的范围超过了最大数组大小:开始 = 0 结束 = 1508715000
【发布时间】:2017-10-23 06:36:51
【问题描述】:

我遇到了这种错误,我找不到同样的问题是这个新问题。我正在使用 PHP7,我怀疑它是否在 memory_limit 上,但我已经将其更改为 1024M。我正在尝试确定日期是否介于两个日期之间。有什么办法或我可以解决这个问题。

function isBetween ($from, $to, $input){
    $input = (is_int($input) ? $input : strtotime($input));
    $from = (is_int($from) ? $from : strtotime($from));
    $to = (is_int($to) ? $to : strtotime($to));

    if(in_array($input, range($from,$to)) ){
        return 1;        
    }
    return 0;
}

【问题讨论】:

标签: php arrays xampp


【解决方案1】:

您不需要创建如此庞大的数组,只需检查日期是否在其他两个日期之间。您所要做的(如果您的日期还没有单位时间戳格式),就是将所有日期转换为 unix 时间戳,然后做一个简单的 if:

if ($startTimestamp < $input && $input < $to) {
    print 'Yay!';
}

【讨论】:

    【解决方案2】:

    我会按照 tkausl 说的做:

    function isBetween ($from, $to, $input){
        $input = (is_int($input) ? $input : strtotime($input));
        $from = (is_int($from) ? $from : strtotime($from));
        $to = (is_int($to) ? $to : strtotime($to));
        return ($input>=$from && $input<=$to)?1:0;  // this is "inclusive" of the start and end
    }
    

    有关阵列限制的信息,您可以从这里开始您的研究之旅:

    【讨论】:

      猜你喜欢
      • 2014-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-16
      • 1970-01-01
      • 2015-01-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多