首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >php回显函数不打印结果

php回显函数不打印结果
EN

Stack Overflow用户
提问于 2018-08-27 06:46:03
回答 2查看 140关注 0票数 -2

我有一个脚本来计算每天票打开的时间,但只有几个小时我们是开放的。函数的细节并不重要,但我已经将其全部粘贴在这里,因为这可能是失败的原因。

下面是函数:

代码语言:javascript
复制
function getTime($o, $now, $total) {

    //One Day in seconds
    $oneDay = 86400;

    //One Business day (12 hours, 7am-7pm)
    $oneBDay = 43200;

    //Get the timestamp of 7am/7pm for time given

    $sevenAM = mktime('7', '0', '0', m($o), d($o), y($o));
    $sevenPM = mktime('19', '0', '0', m($o), d($o), y($o));

    //If Ticket Start Time is before 7am, we only count from 7am after
    if ($o < $sevenAM) {
        $o = $sevenAM;
    } else {
        $o = $o;
    }

    //Debug to get today
    $today = date('Y-m-d h:i:s a', $o);

    //See if we are within the same business day
    $diff = $now - $o;

    //Debug
    //echo $today.",".$timeSpent.",".$total."\n";

    //If we are not within 1 business day, do this again
    if ($diff > $oneBDay) {

        //Total Time spent for the day
        $timeSpent = $sevenPM - $o;

        //Add todays time to total time
        $total = $total + $timeSpent;

        //Move to tomorrow
        $o = $sevenAM + $oneDay;

        getTime($o, $now, $total);
    }

    //If we are within 1 business day, count the time for today and return our result
    if ($diff < $oneBDay) {
        $time = $diff;
        $total = $total + $time; //for example $total = 123456
                    return $total;
            }
}

当我这样做的时候

代码语言:javascript
复制
echo getTime($o,$now,0); 

我预计会看到123456。但我什么都没打印出来。

函数运行,我知道total有一个值(我已经将其静态设置为debug)。

--请注意,如果需要,该函数会调用自身

其他功能:

代码语言:javascript
复制
function y($o){

    $y = date('Y',$o);
    return $y;
}
function m($o){
    $m = date('m',$o);
    return $m;
}
function d($o){
    $d = date('d',$o);
    return $d;
}

编辑:

如果我这样做了:

代码语言:javascript
复制
        if ($diff < $oneBDay) {
        $time = $diff;
        $total = $total + $time; //for example $total = 123456
        echo "My Total:".$total;
                    return $total;
            }

我将看到我的总数:123456

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52030794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档