3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array('Jay', 'Jay', 'Jay', 'Spiders', 'Dogs', 'Cats', 'John', 'John', 'John', 'Dogs', 'Cows', 'Snakes'); $new = array( array_shift( $array)); foreach( $array as $el) { if( !($new[count($new) - 1] === $el)) { $new[] = $el; } } print_r( $new); end( $new); foreach( $new as $el) { echo $el , "\n"; }

preferences:
40.52 ms | 402 KiB | 5 Q