Bylines

Exercise 9 of 9 in chapter 2 · 150 XP · 4 objectives checked by tests

Topics covered: array_map()array_unique()implode()

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

  1. In Sommaire::versHtml(), starting from the articles kept by array_filter() (an ad has no author), build the list of names ($article->auteur->nom) with array_map().
  2. Remove the duplicates with array_unique().
  3. Add to the sentence, before the final period, , by followed by the names separated by , , joined with implode() and escaped with htmlspecialchars().

Reminder

These functions can be chained: array_unique(array_map(…, $articles)) first transforms, then removes duplicates.