How do I properly manipulate and utilize csv data with PHP?
<p>I need some help understanding how to utilize fgetcsv and arrays to manipulate data. I am confused on how to relate the data for multisort to achieve an "ORDER BY $lastNameArray" function without mixing up the data. I sorted ONE of the array elements fine, but the other "array 2" was still the same, leaving it mixed up. How do I properly sort the data, and maintain the data relationship with the other columns on the row so that I can iterate through it and manipulate, echo, print etc. </p>

<p>Error Message: </p>

<blockquote>
  <p>Warning: array_multisort()
  [function.array-multisort]: Argument
  2 is expected to be an array or a sort flag in
  C:\wamp\www\Codelobster2.php on line
  42</p>
</blockquote>

<p>Code that correctly works to loop through csv and show phone number results in a table. This does NOT sort. Besides the sorting, it accomplishes exactly what I need. </p>

<pre><code> &lt;?php 

//table setup
    //print_r($associativeAddressArray);
    //header setup for table output view
    echo "&lt;h1&gt;Phone Directory&lt;/h1&gt;";
    echo "&lt;table border = '1' width = '50%'&gt;\n";
    echo "&lt;tr&gt;";
    echo "&lt;th&gt;Name&lt;/th&gt;";
    echo "&lt;th&gt;Phone Number&lt;/th&gt;";


    //get data from file
    $fileName = 'phoneData.csv';
    $file = fopen($fileName,"r");


    //while not to end of file
    while (!feof($file) ) 
    {

        while (($csv_line = fgetcsv($file)) !== FALSE)
        {
            //print_r($csv_line);
                echo "&lt;tr&gt;";    //beginning new row of record
                echo "&lt;td&gt;" . $csv_line[0] .", ".  $csv_line[1]. "&lt;/td&gt;";  // 0=lastName, 1=FirstName
                echo "&lt;td&gt;" . $csv_line[5] ."-" .  $csv_line[6]. "&lt;/td&gt;";   //
                echo "&lt;/tr&gt;"; //new row
        }
        echo "&lt;/table&gt;\n";
    }
    echo '&lt;FORM&gt;&lt;INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;"&gt;&lt;/FORM&gt;';   //let me know if a better way to do this exists, I'm very limited on html experince

?&gt;
</code></pre>

<p>As a further edit for other students, the final loop to reference the array worked when I did: </p>

<pre><code>//array_multisort($names, $data); // need to sort the data by last name while keeping the seperate arrays in sync
    array_multisort($names, SORT_DESC, $phones, SORT_DESC, $data);

    //Obtain a list of columns
    foreach ($data as $record) 
        {
                echo "&lt;tr&gt;";    //beginning new row of record
                echo "&lt;td&gt;" . $record['name'] . "&lt;/td&gt;";  // 0=lastName, 1=FirstName
                echo "&lt;td&gt;" . $record['phone'] . "&lt;/td&gt;";   //
                echo "&lt;/tr&gt;"; //new row

        } 
</code></pre>
