3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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"; }
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [0] => Jay [1] => Spiders [2] => Dogs [3] => Cats [4] => John [5] => Dogs [6] => Cows [7] => Snakes ) Jay Spiders Dogs Cats John Dogs Cows Snakes