2013-09-24 60 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; 
}