3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $names = array('Anderson','Beresford','Donovan','Amit','Graham'); $alphabet = array(); $previous_letter = ''; foreach($names as $value) { if($value[0] != $previous_letter) { $alphabet[] = $previous_letter = $value[0]; } } print_r($alphabet); ?>
based on VT0Rt
Output for 4.3.0 - 7.2.0
Array ( [0] => A [1] => B [2] => D [3] => A [4] => G )