0

I am trying to sort a list of car names alphabetically. The list is based on a JSON feed that is sorted differently. Car names are nested in a deeper level of the feed. Here's what I have now without sorting:

<?php
$response = file_get_contents( 'http://api.autoit.dk/car/GetCarsExtended/391B093F-BB4A-45AA-BEFF-7B33842401EA' );

$myArray = json_decode($response, true);

foreach($myArray as $item):

    echo $item['FabrikatNavn'].' '.$item['ModelNavn'].' '.$item['VariantBetegnelse'];

?>

Anyone have a suggestion for how to make the list of car names show alphabetically? As you see, the feed comes from this url: http://api.autoit.dk/car/GetCarsExtended/391B093F-BB4A-45AA-BEFF-7B33842401EA

The car names that I want to sort it by are nested inside the feed like this: DealerCarExtended --> FabrikatNavn

Ovesen
  • 23
  • 1
  • 4

1 Answers1

0

You can use the sort($myArray) function.

Check it out here: http://php.net/manual/en/function.sort.php

underflow
  • 483
  • 3
  • 15
  • 2
    `sort()` only works on one-dimensional arrays but not ones like the one OP is dealing with – kero Mar 12 '15 at 23:02
  • Apologies, they could try the array_multisort() function in that case – underflow Mar 12 '15 at 23:05
  • Which should be described in the post which I marked this one a duplicate of (or any of the other ones asking exactly the same question ;) – kero Mar 12 '15 at 23:07
  • 2
    Ha I give up trying to help on this site – underflow Mar 12 '15 at 23:07
  • Sorry if this is a duplicate questions, but non-coders with very limited coding skills like me have difficulties with generic examples or examples from other contexts.. Bear with me ;-) – Ovesen Mar 12 '15 at 23:14