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' => 'Value1-1',
'Attribute2', => 'Value1-2',
'Attribute3', => 'Value1-3'),
array('Attribute1' => 'Value2-1',
'Attribute2', => 'Value2-2',
'Attribute3', => 'Value2-3'),
array('Attribute1' => 'Value3-1',
'Attribute2', => 'Value3-2',
'Attribute3', => '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 < count($dump); $i++) {
$tmp = explode(',', $dump[$i]);
for ($j = 0; $j < count($tmp); $j++) {
$lines[$i][$attributes[$j]] = $tmp[$j];
}
}
I was wondering if there was a more efficient method of completing this task?