<?php
$array = array(10010,10011,10012,10013,10015,10016,10026,10027,10028,10029);
$range = get_num_range($array);
print_r($range);
function get_num_range($arr){
$range = array();
$i = 1;
$tmp_min = $tmp_max = '';
foreach($arr as $no){
//如果没有此range的最小值 第一个就是最小值
if(empty($tmp_min)){
$tmp_min = $no;
}
//下一个值不存在计算出最大值
$next_no = $no+1;
if(!in_array($next_no,$arr) && !empty($next_no)){
$tmp_max = $no;
$range[] = array($tmp_min, $tmp_max);
$tmp_min = '';
}
}
return $range;
}
?>