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++; echo "-- $l --"; } else { echo ">>$el<<"; $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);
Show:  
Copy Clear