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[] = $cur; $l++; echo "-- $l --"; } else { echo ">>$el<<"; $max_l = max($max_l, $l); $res[$max_l] = $seq; $l = 1; } $cur = $el; } $max_l = max($max_l, $l); echo "max: " . $max_l; print_r($seq);
Show:  
Copy Clear