3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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>"; } }
based on Qn49v
Output for 5.6.0 - 7.3.0alpha1
<li> 0 <ul></ul> </li>