0

How do I get the first index of the array, name, with the most amount of characters? The output of the program should be "Camila Cabello".

function artistWithLongestName($artists) {
      // Put your solution here
    };


    $artists = [
  ["name" => "Post Malone", "song" => "Circles", "genre" => "Pop"],
  ["name" => "Camila Cabello", "song" => "Liar", "genre" => "Pop"],
  ["name" => "Tones and I", "song" => "Dance Monkey", "genre" => "Alternative"],
  ["name" => "Billie Eilish", "song" => "Bad Guy", "genre" => "Alternative"],
];

echo "<p>".artistWithLongestName($artists)."</p>";
  • Welcome to Stack Overflow. This site does not exist for doing your job. Please read the How to ask guidelines: https://stackoverflow.com/help/how-to-ask. – Marcel Jan 10 '20 at 22:10
  • 1
    Use `usort()` to sort the array, with a comparison function that compares the length of the `name` elements. Then get the name of the first element. – Barmar Jan 10 '20 at 22:17

0 Answers0