php怎么实现按照1,2,3或者4,5的顺序排列,求解
就是如果有一串数字1,2,3,7,8,怎么才可以把123分到一组,吧7,8分到另一组,就是吧1,2,3和7.8分开
------解决思路----------------------
$s = '1,2,3,7,8';<br />$ar = explode(',', $s);<br />$arr = array();<br />foreach($ar as $v){<br /> $c = count($arr);<br /> if($v == 1 <br><font color='#FF8000'>------解决思路----------------------</font><br> ($v != end($arr[$c-1]) +1)){ <br /> $arr[][] = $v;<br /> }else{<br /> $arr[$c-1][] = $v;<br /> } <br />}<br />print_r($arr);
<br /><?php <br /> $s = '1,2,3,7,8';<br /> $ar = explode(',', $s);<br /> $arr = array();<br /> foreach($ar as $v){<br /> $c = count($arr);<br /> if($v == 1 <br><font color='#FF8000'>------解决思路----------------------</font><br> ($v != end($arr[$c-1]) +1)){ <br /> $arr[][] = $v;<br /> }else{<br /> $arr[$c-1][] = $v;<br /> } <br /> }<br /> <br /> $one = implode(',',$arr[0]);<br /> $two = implode(',',$arr[1]);<br /> <br /> echo "第一次连胜纪录:".$one;<br /> echo "<br>";<br /> echo "第二次连胜纪录:".$two;<br />?><br />