title: Sort by associative column in an array csv
body: <p>I'm trying to sort an array by the 8th column. The column 8 stores data like position 1, position 2, position 3, etc.  col8 has to be associated only with the col7 because col7 holds the answers that should be sorted by the col8. For example, if col8 =position 1 and col7= yellow, col8 =position 2 and col7= black, it should print yellow black.
  I tried to implement all the examples that I found here, but it is not working.</p>
  
  <pre><code>    function readCsv($fileName){
  
      $handle = fopen($fileName, "r");
  
      $data=array();
  
      while ($col = fgetcsv($handle, 1000, ",")) { 
  
          $data[] = [
  
              'Section' =&gt; $col[0],   
              'Q #' =&gt; $col [1],
              'Q Type' =&gt; $col[2],
              'Q Title' =&gt; $col[3],
              'Q Text' =&gt; $col[4],
              'Bonus' =&gt; $col [5],
              'Difficulty' =&gt; $col[6],
              'Answer' =&gt; $col[7],
              'Answer Match' =&gt; $col[8],
              'Responses'=&gt; $col[9], 
  
          ]; 
  
      }
  
     usort($data, function($a, $b) { return strcmp($a["Answer Match"], $b["Answer Match"]); });
  
  
      fclose($handle);
      return $data;
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/nNz5Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nNz5Q.png" alt="enter image description here"></a></p>
  
  <p>Should return yellow black purple.</p>
  
  <p>I try to use this code:</p>
  
  <pre><code>usort($data, function($a, $b) { return strcmp($a["Answer Match"], $b["Answer Match"]); });
  </code></pre>
  
  <p>However, it is sorting Column 1, and not Colum 7.</p>
  
  <p><a href="https://i.stack.imgur.com/TS5Bb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TS5Bb.png" alt="enter image description here"></a></p>
  
  <p>My output is giving incorrect, because it prints the header (# Partipant) and put the participants in alphabetical order:</p>
  
  <p>1> Participant 2    Orange  White Black
  2> # Participant    Black Yellow  Purple</p>
  
  <p>The correct output will be:</p>
  
  <p>1> Participant 1    Yellow Black Purple </p>
  
  <p>2> Participant 2    Orange  Black White</p>