3v4l.org

run code in 300+ PHP versions simultaneously
<?php // user input of years $ar = [1944, 1674, 3021]; // sort the array from lowest to highest $arSorted = sort($ar, SORT_NATURAL | SORT_FLAG_CASE); // find max year $maxCentury = max(...$ar); // get max century $roundedCentury = round($maxCentury, -3); // create a counter $i = 0; foreach(range(0, $roundedCentury, 1000) as $century) { if($century <= $arSorted[$i]) { echo "<li> $century <ul>" . $arSorted[$i++] . "</ul> </li>"; } }

preferences:
53.75 ms | 402 KiB | 5 Q