How to display continuous values ​​in groups? Please give me guidance and help from teachers.
JD26
JD26 2020-04-22 08:53:13
0
1
736

It’s not a database operation, it’s a PHP operation.

For example:

$a="1,2,3,4,5,6,7,8,9,10,11"

$b=" 8,9,10,11,12,13,17,18,19,20"

$c="10,11,12,13,14,15,16,18,20,21, 22,23,24"

Required results

$a="1-11"

$b="8-13,17 -20"

$c="10-16,18,20-24"

Please give me guidance

JD26
JD26

reply all(1)
一锤一座山

Let’s be a bit stupid and split it first $strList = explode(",",$str);

After that, we can loop from the first or last one and compare 1 and -1.

When not equal, output the start bit and end bit, and then continue to the next step of the cycle.

You can also use recursion.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template