Skip to content

Instantly share code, notes, and snippets.

@tamboer
Last active December 14, 2015 21:48
Show Gist options
  • Save tamboer/5153371 to your computer and use it in GitHub Desktop.
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
<?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