Thank you texnixe ! Now I’m grouping my events by year and I sort them. This gives me (as expected) the same result, but I still don’t know how to detect the last entry of each year to announce the next one
But you don’t need to detect this! After the inner loop, you can announce the next year…
<?php
$callback = function($p) {
return $p->datedebut()->toDate('Y');
};
$groupedItems = $articles->group($callback);
foreach($groupedItems as $year => $itemsPerYear): ?>
<!-- Note that for the inner loop you need to loop through $itemsPerYear, not `articles`, or both variables have to be called $articles -->
<?php foreach($itemsPerYear->sortBy('datedebut', 'desc') as $article): ?>
<!-- list of events for the given year... -->
<?php endforeach ?>
<?php echo 'Here comes the next year'; ?>
<?php endforeach ?>