3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $a = "2001-01-01"; $b = "2016-02-15"; $i = date("Y", strtotime($a)); $result = array($i); while($i <= date("Y", strtotime($b))){ echo $i."\n"; array_push($result, $i); if(substr($i, 4, 2) == "12"){ $i = (date("Y", strtotime($i."01")) + 1); } else{ $i++; } } $result = array_slice($result, -10, 10, true); print_r($result);
based on kWXZE
Output for 5.6.0 - 7.3.0beta1
2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 Array ( [7] => 2007 [8] => 2008 [9] => 2009 [10] => 2010 [11] => 2011 [12] => 2012 [13] => 2013 [14] => 2014 [15] => 2015 [16] => 2016 )