How to find out last one year months

Image How to find out last one year months

public function lastYearMonth() {
$months = '';
$year = date('Y');
$numbery = date('y');
$prevyear = $numbery - 1;
$prevyearformat = $year - 1;
$syear = '';
$syearformat = '';
for ($k = 1; $k < 13; $k++) {
$month = date('m', strtotime("+$k month"));
$gety = date('y', strtotime("+$k month"));
if ($gety == $numbery) {
$syear = $prevyear;
$syearformat = $prevyearformat;
} else {
$syear = $numbery;
$syearformat = $year;
}
$months .= "'" . date('M-' . $syear, strtotime("+$k month")) . "',";
}
return $months;
}