Php is arranged in the order of 1, 2, 3, or 4, 5. if there is a string of numbers 1, 2, 3, 7, 8, how can we divide 123 into a group, let's divide 7, 8 into another group, namely, separating 1, 2, 3 and 7.8 ------ solution ---------------------- $ s & nbsp; 1, 2, 3, 7, 8; $ ar & nbsp; & nbsp; explode (, & nbsp; $ php is arranged in the order of 1, 2, 3, or 4, and solved.
If there is a string of numbers 1, 2, 3, 7, 8, how can we divide 123 into one group, 7, 8 into another group, that is, separating 7.8, 3, and?
------ Solution ----------------------
$ S = '1, 2, 3, 7, 8 ';
$ Ar = explode (',', $ s );
$ Arr = array ();
Foreach ($ ar as $ v ){
$ C = count ($ arr );
If ($ v = 1
------ Solution ----------------------
($ V! = End ($ arr [$ C-1]) + 1 )){
$ Arr [] [] = $ v;
} Else {
$ Arr [$ C-1] [] = $ v;
}
}
Print_r ($ arr );
Array
(
[0] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[1] => Array
(
[0] => 7
[1] => 8
)
)
------ Solution ----------------------
$ S = '1, 2, 3, 7, 8 ';
$ Ar = explode (',', $ s );
$ Arr = array ();
Foreach ($ ar as $ v ){
$ C = count ($ arr );
If ($ v = 1
------ Solution ----------------------
($ V! = End ($ arr [$ C-1]) + 1 )){
$ Arr [] [] = $ v;
} Else {
$ Arr [$ C-1] [] = $ v;
}
}
$ One = implode (',', $ arr [0]);
$ Two = implode (',', $ arr [1]);
Echo "first winning streak:". $ one;
Echo"
";
Echo "second winning streak:". $ two;
?>
Running result:
First winning streak: 1, 2, 3
Second Winning streak: 7, 8