実現したいこと
配列に日付を月毎に入れた時に、理想のように出力したい。
ソースコード
php
1 public function get_date_list(){ 2 $now = new DateTime(); 3 $start_date = new DateTime('2022-01'); 4 $date_list = []; 5 for ($date = $start_date; $now >= $date; $date->modify('+1 month')){ 6 $date_list[] = $date; 7 } 8 foreach($date_list as $date){ 9 echo $date->format('Y年m月') . '<br>'; 10 } 11 return $date_list; 12 }
現状
2022年05月
2022年05月
2022年05月
2022年05月
理想
2022年01月
2022年02月
2022年03月
2022年04月
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/04/04 04:08