Assigning array keys based on the values of another array An optimisation question:

Currently I have entities stored in text files in the following format:

Attribute1,Attribute2,Attribute3
Value1-1,Value1-2,Value1-3
Value2-1,Value2-2,Value2-3
Value3-1,Value3-2,Value3-3


And convert it into a 2D array in the following format:

$array = array(array('Attribute1' =&gt; 'Value1-1',
                     'Attribute2', =&gt; 'Value1-2',
                     'Attribute3', =&gt; 'Value1-3'),
               array('Attribute1' =&gt; 'Value2-1',
                     'Attribute2', =&gt; 'Value2-2',
                     'Attribute3', =&gt; 'Value2-3'),
               array('Attribute1' =&gt; 'Value3-1',
                     'Attribute2', =&gt; 'Value3-2',
                     'Attribute3', =&gt; 'Value3-3'));


Using the following PHP code:

$lines = array();
$dump = normaliseNewLine($dump);
$dump = explode("\n", $dump);
$attributes = explode(',', array_shift($dump));

for($i = 0; $i &lt; count($dump); $i++) {
    $tmp = explode(',', $dump[$i]);
    for ($j = 0; $j &lt; count($tmp); $j++) {
        $lines[$i][$attributes[$j]] = $tmp[$j];
    }
}


I was wondering if there was a more efficient method of completing this task?
PHP provides functions to parse CSV files and strings line-by-line.

$file = ...
$headers = fgetcsv($file);
$lines = array();
while (($line = fgetcsv($file)) !== false) {
    $lines[] = array_combine($headers, $line);
}