日期:2014-05-17 浏览次数:20554 次
<?php
$a=array(1,2,5,6,7,8);
$b=array(69,36,23,65,66,67,45);
$c=array(3,4,7,8,10,13,14);
function newarray($arr){
$temp1=array();
$temp2=array();
$temp3=array();
for($i=1;$i<count($arr);$i++){
if($arr[$i] == $arr[$i-1] + 1) {
$temp1[$i-1] = $arr[$i-1];
$temp1[$i] = $arr[$i];
}else {
$temp2=$temp1;
$temp1=array();
}
$temp3= (count($temp2) > count($temp1)) ? $temp2 : $temp1 ;
};
return $temp3;
}
var_dump(newarray($a));
echo "<br/>";
var_dump(newarray($b));
echo "<br/>";
var_dump(newarray($c));
//不能正确返回$c,因为$c可能有3,4/7,8/13,14三种
?>