PHP array get next key/value in foreach()

Viewed 41813

I am looking for a way to get the next and next+1 key/value pair in a foreach(). For example:

$a = array('leg1'=>'LA', 'leg2'=>'NY', 'leg3'=>'NY', 'leg4'=>'FL');

foreach($a AS $k => $v){

    if($nextval == $v && $nextnextval == $v){
       //staying put for next two legs
    }

}
6 Answers
Related