Created
November 3, 2012 00:48
-
-
Save kyleweiner/4005298 to your computer and use it in GitHub Desktop.
PHP: A function that returns an array of years into the future (relative to the current year). Useful dynamically generating credit card expiry years.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// return an array of years relative to the current year | |
function getCreditCardExpiryYears($yearsFromNow = 10) | |
{ | |
if ( ! is_numeric($yearsFromNow)) $yearsFromNow = 10; | |
$thisYear = date('Y'); | |
$untilYear = $thisYear + $yearsFromNow; // e.g. 2012 + 10 = 2022 | |
$years = array(); | |
for ($i = $thisYear; $i <= $untilYear; $i++) | |
{ | |
array_push($years, $i); | |
} | |
return $years; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment