<?php
$n = array (1, 2, 3, 5, 6, 7, 10, 12);
sort ($n); // If necessary.
$i = 0;
while ($i < count ($n))
{
if ($i != 0)
print (", ");
$rangestart = $i;
print ($n [$i++]);
while ($i < count ($n) && $n [$i] == $n [$i - 1] + 1)
$i++;
if ($i > $rangestart + 1)
print (" - " . $n [$i - 1]);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…