3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr1 = [1,2,3,4,45,78,110]; $longestSeq = array(); $tempSeq = array(); $countSeq = 0; $start = true; foreach($arr1 as $arr) { if($start){ $tempSeq[] = $arr; } else { if(end($tempSeq)+1 == $arr){ $tempSeq[] = $arr; } else { $longestSeq = $tempSeq; $tempSeq = array(); } } } var_dump($longestSeq);

preferences:
41.42 ms | 402 KiB | 5 Q