php数组:如何在关联数组中访问“$ key-1”?

时间:2013-09-24 16:49:40

标签: php foreach associative-array

我有一套带有一系列条件的现有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
 }

1 个答案:

答案 0 :(得分: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;
 }