I working on a PHP issue and have an associative array that looks like this:
(
[2019-03-22T2:26:03-04:00] => Array
(
[0] => Array
(
[A] => 1
[B] => 1
[C] => 2
)
)
[2019-03-23T2:27:04-04:00] => Array
(
[0] => Array
(
[A] => 1
)
)
)
I'm trying to turn this data into a CSV that looks like this:
NAME COUNT
2021-07-15T10:46:16-04:00
A 1
B 1
C 2
2021-07-15T10:46:17-04:00
A 1
I've done this before, going from an array to csv, with a simple associative array but getting it in the format above is not working for me. This is the code that I have tried:
The variable $statArray holds the array that I need to be on a CSV.
$fp = fopen('test.csv', 'w');
foreach ($statArray as $fields)
{
foreach ($key as $v)
{
fputcsv($fp, $v);
}
}
Thank you for any help.