title: Sorting multidimensional associative array for a particular key by its value is ascending order
body: <p>I have the following array:</p>
  
  <pre class="lang-none prettyprint-override"><code>Array
  (
  [Bridge Work] =&gt; Array
      (
          [0] =&gt; Array
              (
                  [Name] =&gt; NJ Trunpike_Bridge Repair Work
                  [Location] =&gt; New Jersey
                  [State] =&gt; New Jersey
              )
  
          [1] =&gt; Array
              (
                  [Name] =&gt; Honoapiilani Highway Bridge Truss
                  [Location] =&gt; Maui
                  [State] =&gt; Hawai
              )
  
          [2] =&gt; Array
              (
                  [Name] =&gt; BlueCross Blueshield of Tennessee (Bridge)
                  [Location] =&gt; Memphis
                  [State] =&gt; Tennessee
              )
  
          [3] =&gt; Array
              (
                  [Name] =&gt; Henderson Center Connector Bridge
                  [Location] =&gt; Coquitlam
                  [State] =&gt; British Columbia
              )
  
      )
  
  [Educational] =&gt; Array
      (
          [0] =&gt; Array
              (
                  [Name] =&gt; RTI TASS Complex Admin Bldg
                  [Location] =&gt; Bluffdale
                  [State] =&gt; Utah
              )
  
          [1] =&gt; Array
              (
                  [Name] =&gt; Auburn High School
                  [Location] =&gt; Auburn
                  [State] =&gt; Washington
              )
  
          [2] =&gt; Array
              (
                  [Name] =&gt; Reed College
                  [Location] =&gt; Portland
                  [State] =&gt; Oregon
              )
  
          [3] =&gt; Array
              (
                  [Name] =&gt; Shorewood High School
                  [Location] =&gt; Shoreline
                  [State] =&gt; Washington
              )
  
      )
  
  )
  </code></pre>
  
  <p>Taking in consideration <code>key</code> <code>State</code> and its <code>value</code>, I want to sort it in ascending order.</p>
  
  <p><strong>Expected output:</strong></p>
  
  <pre class="lang-none prettyprint-override"><code>Array
  (
  [Bridge Work] =&gt; Array
      (
          [0] =&gt; Array
              (
                  [Name] =&gt; Henderson Center Connector Bridge
                  [Location] =&gt; Coquitlam
                  [State] =&gt; British Columbia
              )
  
          [1] =&gt; Array
              (
                  [Name] =&gt; Honoapiilani Highway Bridge Truss
                  [Location] =&gt; Maui
                  [State] =&gt; Hawai
              )
  
          [2] =&gt; Array
              (
                  [Name] =&gt; NJ Trunpike_Bridge Repair Work
                  [Location] =&gt; New Jersey
                  [State] =&gt; New Jersey
              )
  
          [3] =&gt; Array
              (
                  [Name] =&gt; BlueCross Blueshield of Tennessee (Bridge)
                  [Location] =&gt; Memphis
                  [State] =&gt; Tennessee
              )
  
      )
  
  [Educational] =&gt; Array
      (
          [0] =&gt; Array
              (
                  [Name] =&gt; Reed College
                  [Location] =&gt; Portland
                  [State] =&gt; Oregon
              )
  
          [1] =&gt; Array
              (
                  [Name] =&gt; RTI TASS Complex Admin Bldg
                  [Location] =&gt; Bluffdale
                  [State] =&gt; Utah
              )
  
          [2] =&gt; Array
              (
                  [Name] =&gt; Auburn High School
                  [Location] =&gt; Auburn
                  [State] =&gt; Washington
              )
  
          [3] =&gt; Array
              (
                  [Name] =&gt; Shorewood High School
                  [Location] =&gt; Shoreline
                  [State] =&gt; Washington
              )
  
      )
  
  )
  </code></pre>
  
  <p><strong>My attempts:</strong></p>
  
  <p>Using <code>usort()</code>:</p>
  
  <pre><code>function cmp($a, $b) 
  {
      return $a["State"] - $b["State"];
  }
  
  usort($project_archives, "cmp");
  
  echo '&lt;pre&gt;'; print_r($project_archives);
  </code></pre>
  
  <p>And using a loop combined with <code>asort()</code>:</p>
  
  <pre><code>function aasort(&amp;$array, $key)
  {
      $sorter = array();
      $ret    = array();
  
      reset($array);
  
      foreach ($array as $ii =&gt; $va) {
          $sorter[$ii] = $va[$key];
      }
  
      asort($sorter);
  
      foreach ($sorter as $ii =&gt; $va) {
          $ret[$ii] = $array[$ii];
      }
  
      $array = $ret;
      return $array;
  }
  
  $sort = aasort($project_archives, "State");
  </code></pre>