我需要一组特定 ISO 周的周一至周五日期。我似乎找不到返回数组的内置方法。我正在使用带有 setISODate 方法的 DateTime 类,如下所示:
$bookingDate = new DateTime();
$bookingWeek = $bookingDate->setISODate($bookingDate->format("Y"), $bookingDate->format("W"));
$bookingDates = array();
$mon = $bookingDate->setISODate($bookingDate->format("Y"), $bookingDate->format("W"), 1);
array_push($bookingDates, $mon);
$tue = $bookingDate->setISODate($bookingDate->format("Y"), $bookingDate->format("W"), 2);
array_push($bookingDates, $tue);
$wed = $bookingDate->setISODate($bookingDate->format("Y"), $bookingDate->format("W"), 3);
array_push($bookingDates, $wed);
$thu = $bookingDate->setISODate($bookingDate->format("Y"), $bookingDate->format("W"), 4);
array_push($bookingDates, $thu);
$fri = $bookingDate->setISODate($bookingDate->format("Y"), $bookingDate->format("W"), 5);
array_push($bookingDates, $fri);
print_r($bookingDates);
但是 - 日期数组的 print_r 每天都返回星期五!有没有办法实现我想要的?