2016-10-20 58 views
-2

我有以下功能拿到2天之间的天数,不包括周末打开返回到变量

function getWorkingDays($startDate, $endDate) 
{ 
    $begin = strtotime($startDate); 
    $end = strtotime($endDate); 
    if ($begin > $end) { 
     echo "startdate is in the future! <br />"; 

     return 0; 
    } else { 
     $no_days = 0; 
     $weekends = 0; 
     while ($begin <= $end) { 
      $no_days++; // no of days in the given interval 
      $what_day = date("N", $begin); 
      if ($what_day > 5) { // 6 and 7 are weekend days 
       $weekends++; 
      }; 
      $begin += 86400; // +1 day 
     }; 
     $working_days = $no_days - $weekends; 

     return $working_days; 


    } 
} 

这工作得很好,但我要如何返回到一个变量来呼应/使用?

+3

$ working_days = getWorkingDays($ start,$ end); –

+0

*你*知道它工作正常吗? –

+0

他可能只是调用函数并在那里回应出结果 –

回答

2

你把它保存到某个变量,然后你可以把它打印出来:

$workingDays = getWorkingDays("some date", "another date"); 
echo $workingDays; 

或者,如果你只是想用它来打印出来,你可以离开了变量:

echo getWorkingDays("some date", "another date"); 
+0

Thanks thats works – Shane