Using the code below, I can create an associative array from a CSV file. It works fine, only problem is, the first key for each row is saved with double quotes (") and I don't understand why.
/* Map Rows and Loop Through Them */
$rows = array_map(function($row) { return str_getcsv($row, ';', '"'); }, file('test.csv'));
$header = array_shift($rows);
$csv = array();
foreach($rows as $row) {
$csv[] = array_combine($header, $row);
}
echo "<pre>";
print_r($csv);
echo "</pre>";
When I print, I get this
Array
(
[0] => Array
(
["TEST"] =>
[EMAIL] => mail@test.com
[NAVN] => Donald Duck
[ADDRESSE] => Paradisæblevej 111
[POSTNRBY] => 1234 Andeby
[TELEFON] => 12345678
[TUR] => 49
[TURNAVN] => Title
[ANTAL] => 1
[BELOEBIALT] => 695
[BONKODE] => 99900714
)
[1] => Array
(
["TEST"] =>
[EMAIL] => mail@test.com
[NAVN] => Donald Duck
[ADDRESSE] => Paradisæblevej 111
[POSTNRBY] => 1234 Andeby
[TELEFON] => 12345678
[TUR] => 49
[TURNAVN] => Title
[ANTAL] => 1
[BELOEBIALT] => 695
[BONKODE] => 99900714
)
)
My header looks like this:
"TEST";"EMAIL";"NAVN";"ADDRESSE";"POSTNRBY";"TELEFON";"TUR";"TURNAVN";"ANTAL";"BELOEBIALT";"BONKODE"
CSV file looks like this:
"TEST";"EMAIL";"NAVN";"ADDRESSE";"POSTNRBY";"TELEFON";"TUR";"TURNAVN";"ANTAL";"BELOEBIALT";"BONKODE"
"";"mail@test.com";"Donald Duck";"Paradisæblevej 111";"1234 Andeby";"12345678";"49";"Title";"1";"695";"99900714"
"";"mail@test.com";"Donald Duck";"Paradisæblevej 111";"1234 Andeby";"12345678";"49";"Title";"1";"695";"99900714"
Note the quotes in "Test"... How can I fix this?
Thanks