title: PHP sorting of multi-dimensional array by price value
body: <p>Say I have a multi-dimensional array set up as follows: </p>
  
  <pre><code>$matrix[1][1]=4.54;        $matrix[2][1]="apples";  $matrix[3][1]="coles";
  $matrix[1][2]=7.2140230;   $matrix[2][2]="apples";  $matrix[3][2]="safeway";
  $matrix[1][3]=15.56;       $matrix[2][3]="oranges"; $matrix[3][3]="coles";
  $matrix[1][4]=2.34;        $matrix[2][4]="bananas"; $matrix[3][4]="safeway";
  $matrix[1][5]=27.98;       $matrix[2][5]="grapes";  $matrix[3][5]="coles";
  $matrix[1][6]=17.68493403; $matrix[2][6]="oranges"; $matrix[3][6]="safeway";
  </code></pre>
  
  <p>And I wish to re-arrange by the pricing information which I've stored under the first 1st column, so that the new order of <code>$matrix</code> would be:</p>
  
  <pre><code>$matrix[1][1]=2.34;        $matrix[2][1]="bananas"; $matrix[3][1]="safeway";
  $matrix[1][2]=4.54;        $matrix[2][2]="apples";  $matrix[3][2]="coles"; 
  $matrix[1][3]=7.2140230;   $matrix[2][3]="apples";  $matrix[3][3]="safeway";
  $matrix[1][4]=15.56;       $matrix[2][4]="oranges"; $matrix[3][4]="coles";
  $matrix[1][5]=17.68493403; $matrix[2][5]="oranges"; $matrix[3][5]="safeway";
  $matrix[1][6]=27.98;       $matrix[2][6]="grapes";  $matrix[3][6]="coles";
  </code></pre>
  
  <p>What would be the best way to achieve this? I've read other questions about sorting multi-dimensional arrays but have had trouble implementing because those examples seemed to have associative arrays with keys and elements, whereas I am just using the different numbers to store each piece of data. I would prefer not to change the way I am storing data in the array as the actual script is quite long and complex and so this would involve a lot of re-work. </p>
  
  <p>I am completely new to PHP so my apologies if I am missing something obvious here. Thanks for your help.</p>
  
  <p>EDIT: Thanks everyone for your advice, scessors code is exactly what I needed. Halfer - to your 1st question - Yes, 2nd post - good point, I will implement this. Thanks again everyone! </p>