title: sort associative array codeigniter php
body: <p>Here is what I want to do:</p>
  
  <pre><code>$newArray = array();
  
  foreach($student as $s){
      $newArray[$s-&gt;id][$s-&gt;grade] = $s;
  }
  </code></pre>
  
  <p>I want to sort the students by their grades (more of a group than a sort) but I just want the grades to be sorted not the id. I could have don't this:</p>
  
  <pre><code>$newArray[$s-&gt;id] = $s-&gt;grade 
  asort($newArray)
  </code></pre>
  
  <p>but I need the remaining data in <code>$s</code>. Also, there is huge chunk of data associated with each student which I want to maintain.</p>
  
  <p>How can I achieve such a sorting?</p>