Trying to get CSV line as 2 dimensional array in PHP
<p>So I'm trying to read a CSV which has a couple of lines and will be compared with a User-Input. This input is an array of id's the user chooses ($talente). The array with the id's will be splitted, the script opens the CSV and reads the line equal to the id's. It works nice but reads the CSV line by line into another one-dimensional array. But I need the lines to be an array already, so that I get a two-dimensional array at the end.</p>

<p>My script so far looks like this:</p>

<pre><code>&lt;?php

$talente = $_GET['talente'];

$talentline = array();

$i = 0;
$myFile = fopen("talente.csv", "r");

foreach ($talente as $talent) {
    if ($talent == $i+1) {          
        while (($data = fgetcsv($myFile, 1000, ",")) !== FALSE) {

            $num = count($data);

                for ($c=0; $c &lt; $num; $c++) {
                    $talentline[][] = $data[$c];
                }

        //$talentline[] = $lines[$i];

        }
        fclose($myFile);
    }
    $i++;

}

print_r(array_values($talentline));

/*echo $talentline[1];
echo $talentline[2];
*/
?&gt;
</code></pre>

<p>The outcome so far is every line with every element, but in a one-dimensional array instead of a two-dimensional:</p>

<pre><code>Array ( [0] =&gt; Array ( [0] =&gt; Schild ) [1] =&gt; Array ( [0] =&gt; 1 ) [2] =&gt; Array ( [0] =&gt; Licht ) [3] =&gt; Array ( [0] =&gt; 1w10 ) [4] =&gt; Array ( [0] =&gt; - ) [5] =&gt; Array ( [0] =&gt; Schutz ) [6] =&gt; Array ( [0] =&gt; 1 ) [7] =&gt; Array ( [0] =&gt; Licht ) [8] =&gt; Array ( [0] =&gt; 1w10 ) [9] =&gt; Array ( [0] =&gt; - ) [10] =&gt; Array ( [0] =&gt; Licht ) [11] =&gt; Array ( [0] =&gt; 4 ) [12] =&gt; Array ( [0] =&gt; Licht ) [13] =&gt; Array ( [0] =&gt; 1w10 ) [14] =&gt; Array ( [0] =&gt; - ) [15] =&gt; Array ( [0] =&gt; Genesung ) [16] =&gt; Array ( [0] =&gt; 1 ) [17] =&gt; Array ( [0] =&gt; Licht ) [18] =&gt; Array ( [0] =&gt; - ) [19] =&gt; Array ( [0] =&gt; - ) [20] =&gt; Array ( [0] =&gt; Aufopfern ) [21] =&gt; Array ( [0] =&gt; 1 ) [22] =&gt; Array ( [0] =&gt; Licht ) [23] =&gt; Array ( [0] =&gt; - ) [24] =&gt; Array ( [0] =&gt; - ) ) 
</code></pre>