title: How can I move an item with a specific property to the top of a PHP array
body: <p>I have an associative array that looks like so:</p>
  
  <pre><code>   {
        "album_6":{
          "name":"02-04-2014",
          "id":6,
          "count":"2",
          "cover":"26974771533c4b57cb0aa"
        },
        "album_3":{
          "name":"Photos of you",
          "id":3,
          "count":"4",
          "cover":"8872935615302242c4fa6c",
          "of_you":true
        }
      }
  </code></pre>
  
  <p>Thy array can contain many items but one of the items will have the extra property <code>of_you</code>.</p>
  
  <p>In the above example it is <code>album_3</code></p>
  
  <p>I would like to move the item that has the <code>of_you</code> property to the first position in the array.  How can I achieve this?</p>
  
  <p>I have tried using <code>usort</code> with a comparison function but it doesn't seem to work.  </p>
  
  <p>Note:  The item could be at any numerical index.</p>
  
  <p><strong>ANSWER:</strong></p>
  
  <p>I found the answer literally straight after posting this question.  The solution is as follows:</p>
  
  <pre><code>  uasort($albums, function($a, $b) {
        return (empty($a['of_you'])) ? 1 : -1;
    });
  </code></pre>
  
  <p>If anyone has a faster/more efficient method.  Please post it as an answer and I will accept.</p>
  
  <p><strong>EDIT:</strong> in order to mantain the associative keys <code>asort()</code> is a better choice in this instance</p>