Given an array of integers, what is the simplest way to iterate over it and figure out all the ranges it covers? for example, for an array such as:
$numbers = ar
I will assume the array X() is pre-sorted (and if not, sort the array before-hand).
for each element of X() as $element (with $i as current array posistion) add $element to end of array Y() if (X($i) + 1 is less than X($i + 1)) AND ($i + 1 is not greater than sizeof(X())) then append Y(1)."-".Y(sizeof(Y())) to end of Z() unset Y() end if next if anything remains in Y() append to end of Z()
well, that's how I would do it.