Get next element in foreach loop
A unique approach would be to reverse the array and then loop. This will work for non-numerically indexed arrays as well: $items = array( ‘one’ => ‘two’, ‘two’ => ‘two’, ‘three’ => ‘three’ ); $backwards = array_reverse($items); $last_item = NULL; foreach ($backwards as $current_item) { if ($last_item === $current_item) { // they match } $last_item … Read more