public static yearList ( integer $from, integer $to = null, boolean $keys = false, boolean $desc = true ) : array | ||
$from | integer | the start year |
$to | integer | the end year |
$keys | boolean | whether to set the array keys same as the values (defaults to false) |
$desc | boolean | whether to sort the years descending (defaults to true) |
return | array |
public static function yearList($from, $to = null, $keys = false, $desc = true)
{
if (static::isEmpty($to)) {
$to = intval(date("Y"));
}
if ($to >= $from) {
$years = $desc ? range($to, $from) : range($from, $to);
return $keys ? array_combine($years, $years) : $years;
} else {
throw new InvalidConfigException("The 'year to' parameter must exceed 'year from'.");
}
}