Home > Backend Development > PHP Tutorial > php如何实现按照1,2,3或者4,5的顺序排列,求解

php如何实现按照1,2,3或者4,5的顺序排列,求解

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:09:23
Original
1628 people have browsed it

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);
Copy after login

Array
(
[0] => Array
(
[0] => 1
[1] => 2
[2] => 3
)

[1] => Array
(
[0] => 7
[1] => 8
)

)
------解决思路----------------------
<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 />
Copy after login

运行结果:

第一次连胜纪录:1,2,3
第二次连胜纪录:7,8

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template