title: How to sort JSON data using PHP & usort?
body: <p>How might I sort the following using PHP? (where wed_2_open comes after wed_1_close)</p>
  
  <p>I have the following JSON data:</p>
  
  <pre><code>"hours": {
    "mon_1_open": 406800,
    "mon_1_close": 437400,
    "tue_1_open": 493200,
    "tue_1_close": 523800,
    "wed_1_open": 579600,
    "wed_1_close": 590400,
    "thu_1_open": 61200,
    "thu_1_close": 91800,
    "fri_1_open": 147600,
    "fri_1_close": 178200,
    "sat_1_open": 237600,
    "sat_1_close": 264600,
    "sun_1_open": 324000,
    "sun_1_close": 345600,
    "wed_2_open": 597600,
    "wed_2_close": 619200
  }
  </code></pre>
  
  <p>Which I then turn into a usable format using JSON_decode:</p>
  
  <pre><code>$obj=json_decode($json);
  </code></pre>
  
  <p>This is put into a loop to use convert it to HTML:</p>
  
  <pre><code>foreach ($obj-&gt;hours as $key =&gt; $val) {
      // Turn array items into HTML list items
  }
  </code></pre>
  
  <p>From <a href="https://stackoverflow.com/questions/887667/sorting-json-output-in-php">previous answers</a> it seems like usort may be an answer, but I get errors telling me $obj is an object rather than an array.</p>
  
  <p>Thanks.</p>