0

My code:

$friends = [
    ['first_name' => "Cassidy", 'last_name' => "Nelson", 'age' => 21],
    ['first_name' => "Kyler", 'last_name' => "Besher", 'age' => 22],
    ['first_name' => "Caitlin", 'last_name' => "McGonigal", 'age' => 19],
    ['first_name' => "Matt", 'last_name' => "Miller", 'age' => 30],
    ['first_name' => "Skyler", 'last_name' =>"Stucky", 'age' => 22]
];

asort($friends);
foreach ($friends as 'first_name' => 'age' {
    echo "$key = $val\n";
}

So I am completely new to PHP so this is probably going to be a pretty dumb question but I am trying to sort the friends within my friends array in order by age while also displaying their first names. What am I doing wrong?

John Slegers
  • 45,213
  • 22
  • 199
  • 169
Remirlis
  • 87
  • 4

0 Answers0