2013-09-24 59 views
0

我得到一个现有的foreach与一组条件,我想保留它,并添加结束日期,这是该行的开始日期之前+一天

我怎么能访问“$ line-1”要做:

foreach($tab as $line){ 
     if the line before with $line[beginning_date] exists 
      $line[end_date]= the line before with $line[beginning_date] value +1 
} 
+0

我认为在你的情况下,你应该使用for循环,这将是直接的。 –

回答

3

够了吗?

$theLineBefore = null; 
foreach($tab as $line){ 
     if the line before with $line[beginning_date] exists 
      $line[end_date]= the line before with $line[beginning_date] value +1 
    $theLineBefore = $line; 
}