I have a CSV which returns me the following array:
Array
(
[0] => Array
(
[0] => ANO
[1] => Sciences
[2] => Mechanics
[3] => Telecom
)
[1] => Array
(
[0] => 2001
[1] => 226
[2] => 27
[3] => 81
)
[2] => Array
(
[0] => 2002
[1] => 433
[2] => 59
[3] => 162
)
[3] => Array
(
[0] => 2003
[1] => 816
[2] => 165
[3] => 647
)
[4] => Array
(
[0] => 2004
[1] => 1098
[2] => 421
[3] => 864
)
)
What I need to turn this array into a json with the following format:
"categories": [
{
"category": [{"label": "2001"}, {"label": "2002"}, {"label": "2003"}, {"label": "2004"}]
}
],
"dataset": [
{
"seriesname": "Sciences",
"data": [{"value": "226"}, {"value": "433"}, {"value": "816"}, {"value": "1098"}]
},
{
"seriesname": "Mechanics",
"data": [{"value": "27"}, {"value": "59"}, {"value": "165"}, {"value": "421"}]
},
{
"seriesname": "Telecom",
"data": [{"value": "81"}, {"value": "162"}, {"value": "647"}, {"value": "864"}]
}
]
I'm breaking my head on this, even though I know it's not so complex, but I'm stuck anyway = /
EDIT 1
Here's what I'm doing:
for ($i=0; $i < count($spreadsheet_data); $i++) {
$chart['categories']['category'][]['label'] = array_shift($spreadsheet_data[$i]);
for ($d=0; $d < count($spreadsheet_data[$i]); $d++) {
$chart['dataset']['data'][]['value'] = $spreadsheet_data[$i][$d];
}
}