- round: documentation ( source)
- sort: documentation ( source)
- max: documentation ( source)
- range: documentation ( source)
<?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>";
}
}