I have a .csv file having first row with headers, I wanna import this file in db using PHP by converting headers as keys of associate array. I have written the code but it gives error, saying combine function should have both arrays of same size, but in reality size of both array is same,
My Code with error is,
$filename = $this->upload_csv_file();
if($filename){
$file = fopen("./uploads/temp/" . $filename, "r");
$csv = array_map('str_getcsv', file("./uploads/temp/" . $filename));
array_walk($csv, function(&$a) use ($csv) {
$a = array_combine($csv[0], $a);
//optional three lines of following code
});
but when I add the following three lines in the array_walk function it tells the same size of both arrays without any error
print_r(count($a). "-");
print_r(count($csv[0]));
exit();
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire