2013-05-15 66 views
0

我有通过检索日期计算员工工作时间的报告,切入和切出和计算时间,这个数据被保存到一个数组中要显示基于工资时期,这里是其基于每周期付款代码在这里(阵列内循环)PHP分组由“每两周”

foreach($punch_sets as $val){ 
    if ($currentmonth==""){ 
     echo "<tr><td>" . date("W",strtotime($val['in_date'])) . "</td>"; 
    } 
    if ($currentmonth1 == date("F",strtotime($val['in_date'])) || $currentmonth1 ==""){ 


     if ($currentmonth == date("W",strtotime($val['in_date'])) || $currentmonth==""){ 
       $total_time += $minSec + $hours*3600; 
       $currentmonth = date("W",strtotime($val['in_date'])); 
      } 
     else 
      { 
       echo "<td>" . sec2hm($total_time) . "</td>"; 
       echo "<td>" . (sec2hm($total_time) * $ratepaid) . "</td></tr></tr>"; 

       $currentmonth =""; 
       $total_time = $minSec + $hours*3600; 
      } 
    } 

    else { 
      $total_time = $minSec + $hours*3600; 
     } 
     $currentmonth1 = date("F",strtotime($val['in_date'])); 
} 

的问题我该如何调整这一逻辑得到每两周计算,而不是每周一次。

回答

0

而不是使用:

通过
date("W",strtotime($val['in_date'])) 

分组,组方:

floor(date("W",strtotime($val['in_date']))/2); 

您可能要更改$currentmonth$currentperiod以反映原始脚本从每月每周的变化现在每两周一次。

+0

好主意,谢谢 –