PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php $in = [1,2,3,5,6,7,8,9]; $cur = array_shift($in); $seq = [$cur]; $res = []; $max_l = 1; $l = 1; foreach($in as $el) { if ($el - $cur === 1) { $seq[] = $el; $l++; } else { $max_l = max($max_l, $l); $res[$max_l] = $seq; $seq = [$el]; $l = 1; } $cur = $el; } $max_l = max($max_l, $l); $res[$max_l] = $seq; echo "max: " . $max_l; print_r($res[$max_l]);
Show:  
Copy Clear