简体   繁体   中英

php array : how to access the “$key-1” in an associative array?

i got an existing foreach with a set of conditions , i'd like to keep it as it is and add the end date that is the beginning date of the line before + one day

How could i access to the "$line-1" to do:

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
 }

Good enough?

$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;
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM