Array => range string function?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Array => range string function?

Post by jraede »

Does anyone know of a good function that takes an array of numbers and turns it into a string representing the ranges?

E.g., array(1,3,4,5,8,9,10,11) would be turned into 1, 3-5, 8-11.

I'm sure there's some out there already and I don't want to reinvent the wheel, but in the event that I have to, what do you think is the best approach?
Post Reply