I have multiple event pages, each with a structure field that can hold multiple dates. For a timetable in the frontend I need to have an array of every unique date (no time).
I tried to loop through every page and pluck the dates from the structure to then loop through this array and only add unique dates to a new array like so:
$events = $site->find('performances', 'workshops')->children();
$uniqueDates = [];
foreach($events as $event) {
$dateStructure = $event->dates()->toStructure();
$dates = $dateStructure->pluck('date');
foreach($dates as $date) {
if(!in_array($date, $uniqueDates)) {
$uniqueDates[] = $date;
}
}
}
But if I var_dump($uniqueDates) it doesn’t filter the reoccurring dates. I am pretty sure it has to do with the fact, that I store a kirby field in that array that is unique even though it has the same content, but I don’t want to just store a string, since I want to work with the date in different formats later on.
What would be the best way to do this?