title: Sorting CSV entries using uasort()
body: <p>I'm trying to sort each student entry by each student's GPA in a descending order. I've been tipped about <code>uasort()</code>, but I'm not sure what associative rules to create, seeing as I'm trying to sort an entire line, based on one entry.<br>
  My database is a CSV file (not ideal, but it's a requirement).</p>
  
  <p>Here's my PHP code:</p>
  
  <pre><code>//Printing out details about each student in a table.
  echo "&lt;table border ='1'&gt;";
  echo "&lt;tr&gt;";
  echo   "&lt;th&gt; Student ID &lt;/th&gt;";
  echo   "&lt;th&gt; First Name &lt;/th&gt;";
  echo   "&lt;th&gt; Last Name &lt;/th&gt;";
  echo   "&lt;th&gt; Birthdate &lt;/th&gt;";
  echo   "&lt;th&gt; Completed Courses &lt;/th&gt;";
  echo   "&lt;th&gt; Failed Courses &lt;/th&gt;";
  echo   "&lt;th&gt; GPA &lt;/th&gt;";
  echo   "&lt;th&gt; Status &lt;/th&gt;";
  echo "&lt;/tr&gt;";
  $data = file("../databases/students.csv");
  foreach ($data as $line){
    $lineArray = explode(',', $line);
    list($studentID, $fName, $lName, $dob, $completedCourses, $failedCourses, $gpa, $status) = $lineArray;
    print &lt;&lt;&lt; HERE
      &lt;tr&gt;
        &lt;td&gt; $studentID &lt;/td&gt;
        &lt;td&gt; $fName &lt;/td&gt;
        &lt;td&gt; $lName &lt;/td&gt;
        &lt;td&gt; $dob &lt;/td&gt;
        &lt;td&gt; $completedCourses &lt;/td&gt;
        &lt;td&gt; $failedCourses &lt;/td&gt;
        &lt;td&gt; $gpa &lt;/td&gt;
        &lt;td&gt; $status &lt;/td&gt;
      &lt;/tr&gt;
  HERE;
  }
  </code></pre>
  
  <p>And here are my entries into the CSV file:
  The entries are (Student ID, First Name, Last Name, D.O.B, Courses Completed, Courses failed, GPA, Status)</p>
  
  <pre class="lang-none prettyprint-override"><code>1, Emma, Zento, 07.03.97, 10, 2, 3.2, Honour,
  2, Milo, Aniris, 04.12.02, 6, 0, 5, High Honour,
  3, Akatsuki, Sato, 12.12.01, 3, 3, 2.1, Satisfactory,
  4, Natsuki, Ito, 01.01.02, 6, 0, 4.0, High Honour,
  </code></pre>
  
  <p>Ideally it should be rendered like this with the help of the <code>uasort</code> function:</p>
  
  <pre class="lang-none prettyprint-override"><code>2, Milo, Aniris, 04.12.02, 6, 0, 5, High Honour,
  4, Natsuki, Ito, 01.01.02, 6, 0, 4.0, High Honour,
  1, Emma, Zento, 07.03.97, 10, 2, 3.2, Honour,
  3, Akatsuki, Sato, 12.12.01, 3, 3, 2.1, Satisfactory,
  </code></pre>
  
  <p>Not sure if this is considered an open question, but I don't know where else to ask for help.</p>