title: Sorting by key in a multidimensional array with php
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2059255/sorting-multidimensional-array-in-php">Sorting multidimensional array in PHP</a>  </p>
  </blockquote>
  
  
  
  <p>How can I sort by key in a multidimensional array?</p>
  
  <p>For instance, below is the array I print from my db, where the <strong>latest</strong> comes first - <strong>December, November, October, etc</strong> and <strong>2011, 2010, 2009, etc</strong></p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [URL] =&gt; september 2011
              [Title] =&gt; September 2011
              [Date] =&gt; 8
              [Month] =&gt; 9
              [Year] =&gt; 2011
          )
  
      [1] =&gt; Array
          (
              [URL] =&gt; january 2011
              [Title] =&gt; January 2011
              [Date] =&gt; 1
              [Month] =&gt; 2
              [Year] =&gt; 2011
          )
  
      [2] =&gt; Array
          (
              [URL] =&gt; february 2011
              [Title] =&gt; February 2011
              [Date] =&gt; 4
              [Month] =&gt; 1
              [Year] =&gt; 2011
          )
  
      [3] =&gt; Array
          (
              [URL] =&gt; november 2011
              [Title] =&gt; November 2011
              [Date] =&gt; 23
              [Month] =&gt; 11
              [Year] =&gt; 2010
          )
  
      [4] =&gt; Array
          (
              [URL] =&gt; april 2011
              [Title] =&gt; April 2011
              [Date] =&gt; 23
              [Month] =&gt; 4
              [Year] =&gt; 2010
          )
  
  )
  </code></pre>
  
  <p>But I need it to be like this, <strong>October, November, December, etc</strong> and <strong>2011, 2010, 2009, etc</strong> - note the months are sorted by the <strong>oldest</strong> comes first but the years are still sorted by the <strong>latest</strong> comes first.</p>
  
  <p>So the array should be sorted like this,</p>
  
  <pre><code>Array
  (
  
      [2] =&gt; Array
          (
              [URL] =&gt; february 2011
              [Title] =&gt; February 2011
              [Date] =&gt; 4
              [Month] =&gt; 1
              [Year] =&gt; 2011
          )
  
      [1] =&gt; Array
          (
              [URL] =&gt; january 2011
              [Title] =&gt; January 2011
              [Date] =&gt; 1
              [Month] =&gt; 2
              [Year] =&gt; 2011
          )
  
      [0] =&gt; Array
          (
              [URL] =&gt; september 2011
              [Title] =&gt; September 2011
              [Date] =&gt; 8
              [Month] =&gt; 9
              [Year] =&gt; 2011
          )
  
      [4] =&gt; Array
          (
              [URL] =&gt; april 2010
              [Title] =&gt; April 2010
              [Date] =&gt; 23
              [Month] =&gt; 4
              [Year] =&gt; 2010
          )
  
      [3] =&gt; Array
          (
              [URL] =&gt; november 2010
              [Title] =&gt; November 2010
              [Date] =&gt; 23
              [Month] =&gt; 11
              [Year] =&gt; 2010
          )
  )
  </code></pre>
  
  <p>Is that possible?</p>