title: PHP: how to usort and maintain keys?
body: <p>I have the following array (JSON-ified for ease of viewing):</p>
  
  <pre><code>{
    "23": {
      "price": "33.99"
    },
    "38": {
      "price": "30.86"
    },
    "51": {
      "price": "31.49"
    }
  }
  </code></pre>
  
  <p>I want to sort this by the <code>price</code> key, but I want the results to also return the key of the element that contains the price, so something like this:</p>
  
  <pre><code>{
    "38": {
      "price": "30.86"
    },
    "51": {
      "price": "31.49"
    },
    "23": {
      "price": "33.99"
    }
  }
  </code></pre>
  
  <p>My <code>usort</code> callback is this:</p>
  
  <pre><code>private function _price_sort($a, $b)
  {
      if ($a['price'] == $b['price']) {
          return 0;
      }
      return ($a['price'] &lt; $b['price']) ? -1 : 1;
  }
  </code></pre>
  
  <p>... which returns the array in the correct order, but without the element container:</p>
  
  <pre><code>[
    {
      "price": "30.86"
    },
    {
      "price": "31.49"
    },
    {
      "price": "33.99"
    }
  ]
  </code></pre>
  
  <p>Is there something I need to do in the callback function or in usort to retain the keys?</p>