I have this array:
$users = Array
(
[Gareth] => Array
(
[25732] => 180
[25689] => 2310
[25760] =>
[25759] =>
[25758] =>
[25728] =>
[25734] =>
)
[Adam] => Array
(
[25732] =>
[25689] =>
[25760] =>
[25759] =>
[25758] => 420
[25728] => 60
[25734] =>
)
[Cennydd ] => Array
(
[25732] =>
[25689] =>
[25760] =>
[25759] =>
[25758] =>
[25728] =>
[25734] => 1035
)
)
It has users with ids of work and the duration they've spent on that work in minutes.
I need to output this data using highcharts
so it needs to be in a Json format.
Currently, using json_encode
, it returns:
{ "Gareth":
{
"25732":180,"25689":2310,"25760":null,"25759":null,"25758":null,"25728":null,"25734":null
},
"Adam Jukes":
{
"25732":null,"25689":null,"25760":null,"25759":null,"25758":420,"25728":60,"25734":null
},
"Cennydd":
{
"25732":null,"25689":null,"25760":null,"25759":null,"25758":null,"25728":null,"25734":1035
}
}
But I need this in the format:
[{
"name": 'Gareth ',
"data": [180, 2310,null, null, null,null, null]
},
{ "name": 'Adam',
"data": [null, null, null,null,420, 60, null]
},{
"name": 'Cennydd',
"data":[null, null , null, null, null,null, 1035 ]
}]
}]
But I can't seem to figure it out.
Do I need to use a foreach
to separate and create a new array with the right format?