<?php $dates = ['20240228', '20240229', '20240301']; function formatDates(array $datesInput) { foreach ($datesInput as $datesKey => $date) { $date = new DateTime($date); $month = $date->format('F'); $day = $date->format('j'); if ($datesKey == 0) { $datesOutput = $day; } elseif ($currentMonth <> $month) { $datesOutput .= " $currentMonth & $day"; } else { $datesOutput .= ", $day"; } $currentMonth = $month; } return "$datesOutput $month"; } echo formatDates($dates);
You have javascript disabled. You will not be able to edit any code.