Hey guys I'm geting a file CSV and when use print I have the output
$excelImoveis = $request->file('excel_imoveis');
$filePath = $excelImoveis->getRealPath();
$file = fopen($filePath, 'r');
$header = fgetcsv($file);
$array = [];
dd($header);
while (($columns = fgetcsv($file, 1000, ';')) !== FALSE) {
dd($header);
$array[] = array_combine(array_filter($header), array_filter($columns));
}
Outupu
array:1 [▼
0 => b"Código do Imóvel;FotoImovel;destaque;ordem"
]
How to remove "b" this item ? maybe this implied the error of array_conbine():
$array[] = array_combine(array_filter($header), array_filter($columns));
Error: array_combine(): Both parameters should have an equal number of elements
更改读取文件头的行以使用正确的分隔符
$header = fgetcsv($file, 1000, ';');
array_filter
removes empty-evaluated values (such as 0
, "0"
, ""
, null
, false
). So if one of your column has empty value, the number of elements will be different with header's and array_combine
will fail.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.