Last active
December 14, 2015 21:48
-
-
Save tamboer/5153371 to your computer and use it in GitHub Desktop.
php function returns array with the n next years, current year and n previous years
This file contains 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
<?php | |
/** | |
* | |
* returns array with the next ($next*)years, current year and previous (previous*)years | |
* return as int | |
* (except for current, needs to change) | |
* | |
*/ | |
public function getNextAndPreviousYears($current,$next = null,$previous = null){ | |
$years = array(); | |
for($j=$previous;$j>=1;$j--){ | |
$new = date('Y', strtotime('-'.$j.' year')); | |
array_push($years,$new); | |
} | |
array_push($years,$current); | |
for($i=1;$i<=$next;$i++){ | |
$new = date('Y', strtotime('+'.$i.' year')); | |
array_push($years,$new); | |
} | |
return $years; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment