Php 把回报变成变量
我有下面的函数来获取2天之间的天数,不包括周末Php 把回报变成变量,php,function,Php,Function,我有下面的函数来获取2天之间的天数,不包括周末 function getWorkingDays($startDate, $endDate) { $begin = strtotime($startDate); $end = strtotime($endDate); if ($begin > $end) { echo "startdate is in the future! <br />"; return 0;
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;
}
}
函数getWorkingDays($startDate,$endDate)
{
$begin=STROTTIME($startDate);
$end=strottime($endDate);
如果($begin>$end){
echo“startdate在未来!”; 返回0; }否则{ $no_days=0; $weekends=0; 而($begin 5){//6和7是周末 $weekends++; }; $begin+=86400;//+1天 }; $工作日=$无工作日-$周末; 返回$working_天; } }
这很好,但是如何将返回值转换为变量以进行回显/使用?您可以将其保存到某个变量中,然后将其打印出来:
$workingDays = getWorkingDays("some date", "another date");
echo $workingDays;
或者,如果您只想使用它打印出来,您可以省去变量:
echo getWorkingDays("some date", "another date");
$working_days=getWorkingDays($start,$end);你怎么知道它工作得很好?他可能只是调用了这个函数,并在其中重复了结果。你需要学习基本的PHP:@ManuelMannhardt-谢谢