- round: documentation ( source)
- max: documentation ( source)
- range: documentation ( source)
<?php
// user input of years
$ar = [1944, 1674, 3021];
// find max year
$maxCentury = max(...$ar);
// get max century
$roundedCentury = round($maxCentury, -3);
foreach($ar as $year) {
foreach(range(0, $roundedCentury, 1000) as $century) {
if($century <= $year) {
echo "<li> $century <ul>" . $year . "</ul> </li>";
}
}
}