使用 Carbon 获取上个月的最后 5 天

Get the last 5 days of last month using Carbon

我只想使用 carbon 获取上个月的最后 5 天

我正在使用此代码获取上个月的最后一天

$lastDay = new Carbon('last day of last month')

我已经在互联网上搜索了,但找不到答案

我已经有了答案

$lastDay = new Carbon('last day of last month');
$lastMonthDays = [];
$lastDays = $lastDay->format('d') - 5;
$day = $lastDay->format('d');

for($i = $lastDays +1 ; $i <= $day; $i++){
  $lastMonthDays[] = $i;
}