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