Retorno de arquivo .csv
Boa tarde pessoal, peço uma ajuda a vcs se possível.
Tenho um arquivo .csv com os dados abaixo:
CEP PESO ALTURA LARGURA COMPRIMENTO
83602230 2 16 16 16
5060000 1 8 8 8
Meu código é esse:
<?php
header('Content-Type: application/json');
$file="paulo.csv";
$csv= file_get_contents($file);
$array = array_map("str_getcsv", explode("\n", $csv));
$json = json_encode($array, JSON_PRETTY_PRINT);
print_r($json);
?>
Com meu código, tenho o seguinte retorno:
[
[
"CEP;PESO;ALTURA;LARGURA;COMPRIMENTO"
],
[
"83602230;2;16;16;16"
],
[
"5060000;1;8;8;8"
],
[
null
]
]
Mas eu preciso desse retorno abaixo
[
{
"CEP":83602230,
"PESO":2,
"ALTURA":16,
"LARGURA":16,
"COMPRIMENTO":16
},
{
"CEP":5060000,
"PESO":1,
"ALTURA":8,
"LARGURA":8,
"COMPRIMENTO":8
}
]
Discussão (8)
Carregando comentários...