Use uasort to sort elements in an array <p>I have the following array</p> <pre><code>$array = array( 'note' =&gt; array('test', 'test1', 'test2', 'test3', 'test4'), 'year' =&gt; array('2011','2010', '2012', '2009', '2010'), 'type' =&gt; array('journal', 'conference', 'conference', 'conference','conference'), ); </code></pre> <p>And I would like to sort the elements using <code>uasort()</code> and array <code>year</code>.</p> <p>I did:</p> <pre><code>function cmp($a, $b) { if($a['year'] == $b['year']) return 0; return ($a['year'] &lt; $b['year']) ? -1 : 1; } uasort($array,'cmp'); print_r($array); </code></pre> <p>But the output is incorrect:</p> <pre><code>Array ( [type] =&gt; Array ( [0] =&gt; journal [1] =&gt; conference [2] =&gt; conference [3] =&gt; conference [4] =&gt; conference ) [year] =&gt; Array ( [0] =&gt; 2011 [1] =&gt; 2010 [2] =&gt; 2012 [3] =&gt; 2009 [4] =&gt; 2010 ) [note] =&gt; Array ( [0] =&gt; test [1] =&gt; test1 [2] =&gt; test2 [3] =&gt; test3 [4] =&gt; test4 ) ) </code></pre> <p>Desired output:</p> <pre><code>Array ( [type] =&gt; Array ( [0] =&gt; conference [1] =&gt; journal [2] =&gt; conference [3] =&gt; conference [4] =&gt; conference ) [year] =&gt; Array ( [0] =&gt; 2012 [1] =&gt; 2011 [2] =&gt; 2010 [3] =&gt; 2010 [4] =&gt; 2009 ) [note] =&gt; Array ( [0] =&gt; test2 [1] =&gt; test [2] =&gt; test1 [3] =&gt; test4 [4] =&gt; test3 ) ) </code></pre>