title: How to sort json string by value in a loop?
body: <p>I have the following json string that I want to sort in the format A-Z. </p>
  
  <pre><code>{
      "buses": 
      [
              {
                  "name": "Shuttle 10: City 1 - City 5 (11 seats left)",
                  "id": 12
              },
              {
                  "name": "Shuttle 11: City 1 - City 5 (11 seats left)",
                  "id": 13
              },
              {
                  "name": "Shuttle 12: City 1 - City 5 (11 seats left)",
                  "id": 14
              },
              {
                  "name": "Shuttle 13: City 1 - City 5 (11 seats left)",
                  "id": 15
              },
              {
                  "name": "Shuttle 14: City 1 - City 5 (11 seats left)",
                  "id": 16
              },
              {
                  "name": "Shuttle 15: City 1 - City 5 (11 seats left)",
                  "id": 17
              },
              {
                  "name": "Shuttle 16: City 1 - City 5 (11 seats left)",
                  "id": 18
              },
              {
                  "name": "Shuttle 17: City 1 - City 5 (11 seats left)",
                  "id": 19
              },
              {
                  "name": "Shuttle 18: City 1 - City 5 (10 seats left)",
                  "id": 20
              },
              {
                  "name": "Shuttle 19: City 1 - City 5 (11 seats left)",
                  "id": 21
              },
              {
                  "name": "Shuttle 1: City 1 - City 5 (10 seats left)",
                  "id": 1
              },
              {
                  "name": "Shuttle 20: City 1 - City 5 (11 seats left)",
                  "id": 22
              },
              {
                  "name": "Shuttle 21: City 1 - City 5 (11 seats left)",
                  "id": 23
              },
              {
                  "name": "Shuttle 22: City 1 - City 5 (11 seats left)",
                  "id": 24
              },
              {
                  "name": "Shuttle 23: City 1 - City 5 (11 seats left)",
                  "id": 25
              },
              {
                  "name": "Shuttle 24: City 1 - City 5 (11 seats left)",
                  "id": 26
              },
              {
                  "name": "Shuttle 25: City 1 - City 5 (11 seats left)",
                  "id": 27
              },
              {
                  "name": "Shuttle 26: City 1 - City 5 (11 seats left)",
                  "id": 28
              },
              {
                  "name": "Shuttle 27: City 1 - City 5 (11 seats left)",
                  "id": 29
              },
              {
                  "name": "Shuttle 28: City 1 - City 5 (11 seats left)",
                  "id": 30
              },
              {
                  "name": "Shuttle 29: City 1 - City 5 (11 seats left)",
                  "id": 31
              },
              {
                  "name": "Shuttle 2: City 1 - City 5 (2 seats left)",
                  "id": 3
              }
          ]
  }
  </code></pre>
  
  <p>So basically I want to sort the string in ascending order A-Z where the result will have this occur first:</p>
  
  <pre><code>{
      "name": "Shuttle 1: City 1 - City 5 (10 seats left)",
      "id": 1
  }
  </code></pre>
  
  <p>And this as the last.</p>
  
  <pre><code>    {
          "name": "Shuttle 29: City 1 - City 5 (11 seats left)",
          "id": 31
      }
  </code></pre>
  
  <p>I have held the json string in a variable <code>$result</code> and trying the sort function does not work. </p>
  
  <pre><code>$json = json_decode($result, true);
  echo sort($json);
  </code></pre>
  
  <p>What is the best way to achieve this using sort in php and return the sorted json string?</p>