Skip to content

Instantly share code, notes, and snippets.

@SebbeJohansson
Created May 17, 2019 14:42
Show Gist options
  • Save SebbeJohansson/8f5071c3b7689d6414f854a366bc26fc to your computer and use it in GitHub Desktop.
Save SebbeJohansson/8f5071c3b7689d6414f854a366bc26fc to your computer and use it in GitHub Desktop.
$row = 1;
$keys = [];
$array = [];
if (($handle = fopen("themes/fritidsfabriken/docs/feature_value_export_CZ_en.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
//echo "<p> $num fields in line $row: <br /></p>\n";
$value = [];
for ($c=0; $c < $num; $c++) {
//echo $data[$c] . "<br />\n";
if($row == 1){
$keys[] = $data[$c];
}else{
$value[$keys[$c]] = trim($data[$c]);
}
}
//var_dump($value);
if($row != 1){
$array[] = $value;
}
$row++;
}
fclose($handle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment