Merging overlapping ranges in PHP arrays?

larhrdsagon676

New Member
I have an array in the following format:\[code\]array( 0 => array(1, 5), 1 => array(4, 8), 2 => array(19, 24), 3 => array(6, 9), 4 => array(11, 17),);\[/code\]Where each item is a X-to-Y range. What I would like to merge the overlapping ranges in the array, to get something more like this:\[code\]array( 0 => array(1, 9), // 1-5, 4-8 and 6-9 are overlapping, so they are merged 1 => array(11, 17), 2 => array(19, 24),);\[/code\]What would be the best way to accomplish this?
 
Back
Top