Converting array elements into range in php
I’m working on an array of numeric values. I have a array of numeric values as the following in PHP 11,12,15,16,17,18,22,23,24 And I’m trying to convert it into range for e.g in above case it would be: 11-12,15-18,22-24 I don’t have any idea how to convert it into range. You have to code it yourself ;-) The algorithm is quite simple: Iterate over the items. Remember the previous item and the start of the range. For each item (except the first one) check: If currentItem = prevItem + 1 then you haven't found a new range. Continue. Otherwise your range has ended. Write down the range. You have