title: Sort Multidimensional arrays by sub array key value
body: <p>There are similar questions and answers posted for this, but none of them quite match the structure of my array, so apologies if I missed something. This is an array generated by the WordPress wpdb class:</p>
  
  <pre><code>Array ( 
  [0] =&gt; Array ( [meta_id] =&gt; 37850 [post_id] =&gt; 5548 [meta_key] =&gt; Item # [meta_value] =&gt; 66002 ) 
  [1] =&gt; Array ( [meta_id] =&gt; 37851 [post_id] =&gt; 5548 [meta_key] =&gt; Hex Size [meta_value] =&gt; .051" ) 
  [2] =&gt; Array ( [meta_id] =&gt; 37852 [post_id] =&gt; 5548 [meta_key] =&gt; Across Flats [meta_value] =&gt; 0.051 ) 
  [3] =&gt; Array ( [meta_id] =&gt; 37853 [post_id] =&gt; 5548 [meta_key] =&gt; Type [meta_value] =&gt; Hexagonal ) 
  [4] =&gt; Array ( [meta_id] =&gt; 37854 [post_id] =&gt; 5548 [meta_key] =&gt; Shank [meta_value] =&gt; .315" ) ) 
  
  Array ( 
  [0] =&gt; Array ( [meta_id] =&gt; 37910 [post_id] =&gt; 5553 [meta_key] =&gt; Item # [meta_value] =&gt; 66008 ) 
  [1] =&gt; Array ( [meta_id] =&gt; 37911 [post_id] =&gt; 5553 [meta_key] =&gt; Hex Size [meta_value] =&gt; 1/8" ) 
  [2] =&gt; Array ( [meta_id] =&gt; 37912 [post_id] =&gt; 5553 [meta_key] =&gt; Across Flats [meta_value] =&gt; 0.127 ) 
  [3] =&gt; Array ( [meta_id] =&gt; 37913 [post_id] =&gt; 5553 [meta_key] =&gt; Type [meta_value] =&gt; Hexagonal ) 
  [4] =&gt; Array ( [meta_id] =&gt; 37914 [post_id] =&gt; 5553 [meta_key] =&gt; Shank [meta_value] =&gt; .315" ) ) 
  
  Array ( 
  [0] =&gt; Array ( [meta_id] =&gt; 37862 [post_id] =&gt; 5549 [meta_key] =&gt; Item # [meta_value] =&gt; 66004 ) 
  [1] =&gt; Array ( [meta_id] =&gt; 37863 [post_id] =&gt; 5549 [meta_key] =&gt; Hex Size [meta_value] =&gt; 1/16" ) 
  [2] =&gt; Array ( [meta_id] =&gt; 37864 [post_id] =&gt; 5549 [meta_key] =&gt; Across Flats [meta_value] =&gt; 0.063 ) 
  [3] =&gt; Array ( [meta_id] =&gt; 37865 [post_id] =&gt; 5549 [meta_key] =&gt; Type [meta_value] =&gt; Hexagonal ) 
  [4] =&gt; Array ( [meta_id] =&gt; 37866 [post_id] =&gt; 5549 [meta_key] =&gt; Shank [meta_value] =&gt; .315" ) ) 
  
  Array ( 
  [0] =&gt; Array ( [meta_id] =&gt; 37886 [post_id] =&gt; 5551 [meta_key] =&gt; Item # [meta_value] =&gt; 66006 ) 
  [1] =&gt; Array ( [meta_id] =&gt; 37887 [post_id] =&gt; 5551 [meta_key] =&gt; Hex Size [meta_value] =&gt; 3/32" ) 
  [2] =&gt; Array ( [meta_id] =&gt; 37888 [post_id] =&gt; 5551 [meta_key] =&gt; Across Flats [meta_value] =&gt; 0.095 ) 
  [3] =&gt; Array ( [meta_id] =&gt; 37889 [post_id] =&gt; 5551 [meta_key] =&gt; Type [meta_value] =&gt; Hexagonal ) 
  [4] =&gt; Array ( [meta_id] =&gt; 37890 [post_id] =&gt; 5551 [meta_key] =&gt; Shank [meta_value] =&gt; .315" ) ) 
  </code></pre>
  
  <p>I need to list them by order of Array[meta_value]. Then I use the array to generate a table of products in that order. I have been working with the following function, but it produces a result that doesn't make any sense:</p>
  
  <pre><code>function subval_sort($a,$subkey) {
      foreach($a as $k=&gt;$v) {
          $b[$k] = strtolower($v[$subkey]);
      }
      asort($b);
      foreach($b as $key=&gt;$val) {
          $c[] = $a[$key];
      }
      return $c;
  }
  </code></pre>