Gaston is miffed: the table of contents counts his articles, but doesn't say who wrote them. So Madame Lou adds the bylines: “In this issue: 4 articles and 1 classified ad, by Madame Lou, Gaston, Odette.” Gaston wrote two articles, but his name appears only once.
Your mission
- In
Sommaire::versHtml(), starting from the articles kept byarray_filter()(an ad has no author), build the list of names ($article->auteur->nom) witharray_map(). - Remove the duplicates with
array_unique(). - Add to the sentence, before the final period,
, byfollowed by the names separated by,, joined withimplode()and escaped withhtmlspecialchars().
Reminder
array_map(fn ($x) => …, $tableau)returns an array of the function's results, one per element. Careful: here the array comes second, the opposite ofarray_filter().array_unique($tableau)removes duplicates.implode(', ', $tableau)glues the elements into a single string, separated by,.
These functions can be chained: array_unique(array_map(…, $articles)) first transforms, then removes duplicates.