How does php arrange and solve the problem in the order of 1, 2, 3, or 4, 5?

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.