kartik\helpers\Enum::yearList PHP Method

yearList() public static method

Example: ~~~ $years = Enum::yearList(2000, 2013); // years from 2000 to 2013 echo $years[0]; // returns 2013 echo $years[12]; // returns 2000 $years = Enum::yearList(2000, 2013, false, false); // years from 2000 to 2013 echo $years[0]; // returns 2000 echo $years[12]; // returns 2013 ~~~
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'.");
        }
    }