Skip to content
Advertisement

When trying to export this array as a CSV file in php I get an empty sheet

I have this array, and I want to convert it into a CSV file, the problem, is that the array does not generate a csv properly, but just empty fields, why?

Here’s my array contents (the array that I’m printing here is $listaParaCSV, as the code shown below):

JavaScript

And here is my code (the variables $listaFechas and $paraCSV are arrays themselves):

JavaScript

The expected result is a CSV file that when opened with open with OpenCalc or excel shows something like this:

enter image description here

Advertisement

Answer

The problem is that you are looping over the $listaParaCSV with has 2 elements, the headers and then all the data in one element.

Instead, if you write out the headers and then loop over $paraCSV, adding the key (the name) as the first field before outputting them…

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement