怎样检测数组里数据为连续的3位数?
------解决方案--------------------
- PHP code
$arr = array(4,7,0,2,4,5,6,9,1,2,3,4);$counter = 1;for($i = 0; $i < count($arr) - 1; $i ++) { if ($arr[$i + 1] == $arr[$i] + 1) { $counter ++; if ($counter == 3) { echo "<pre>找到连续值的数字:\n[".($i - 1)."]=>{$arr[$i - 1]}\n[".$i."]=>{$arr[$i]}\n[".($i + 1)."]=>{$arr[$i + 1]}\n</pre>"; } } else $counter = 1;}