[PHP] 対象月1ヶ月の日付を配列で取得する方法
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfxhKxfx1ZdjgFq8DHiq_JU0kz2t6h2N08376djrkt5uOjHQqX4-t42KPQ7nordgoW6Ueg9VGXqNmn3OUdLCphic82OmFfx4CpWdzWYhoLmfIQPFqK5p10Xh0R5hmKF5iOHJCHtanil8F0u6Xt43GFDpUDIftRFEtUSOip8lt7_Ves_UlW7BFajZln/s1600/php2.png)
function get_dates($year=null, $month=null){
$y = $year;
$m = sprintf("%02d", (int)$month);
$first_day = "{$y}-{$m}";
$dates = [];
for($i=(int)date('d', strtotime($first_day)); $i<=(int)date('d', strtotime("{$first_day} last day of this month")); $i++){
$d = sprintf("%02d", $i);
$dates[] = "{$y}-{$m}-{$d}";
}
return $dates;
}