You are here

public static function PersianDateHelper::years in Persian Date for Drupal 8 8.4

Same name and namespace in other branches
  1. 8 src/PersianDateHelper.php \Drupal\persian_date\PersianDateHelper::years()

Constructs an array of years in a specified range.

Parameters

int $min: (optional) The minimum year in the array. Defaults to zero.

int $max: (optional) The maximum year in the array. Defaults to zero.

bool $required: (optional) If FALSE, the returned array will include a blank value. Defaults to FALSE.

Return value

array An array of years in the selected range.

Overrides DateHelper::years

File

src/PersianDateHelper.php, line 275

Class

PersianDateHelper

Namespace

Drupal\persian_date

Code

public static function years($min = 0, $max = 0, $required = FALSE) {

  // Ensure $min and $max are valid values.
  if (empty($min)) {
    $min = intval(date('Y', REQUEST_TIME) - 3);
  }
  if (empty($max)) {
    $max = intval(date('Y', REQUEST_TIME) + 3);
  }
  $none = [
    '' => '',
  ];
  $range = range($min, $max);
  $range = array_combine($range, $range);
  return !$required ? $none + $range : $range;
}