Reputation: 450
I have the following array:
Array
(
[0] => Array
(
[0] => 2015-07-18
[1] => 22 SSH
)
[1] => Array
(
[0] => 2015-07-18
[1] => 80 HTTP
)
[2] => Array
(
[0] => 2015-07-18
[1] => 3389 Remote Desktop
)
[3] => Array
(
[0] => 2015-07-19
[1] => 3389 Remote Desktop
)
[4] => Array
(
[0] => 2015-07-19
[1] => 3389 Remote Desktop
)
)
and the following function to bring the data in the needed format/array for highcharts:
$result = array();
$result[0] = array();
$result[0][data] = array();
foreach ($stack_stats_timeline as $key => &$value) {
if(!in_array($value[0], $result[0][data], true)) array_push($result[0][data], $value[0]);
$hash = $value[1];
$result[$hash][name] = $value[1];
$result[$hash][data][$value[0]] += 1;
}
so far so good... hoever the problem is that when i do
$result = json_encode($result);
print_r($result);
I get
[{"data":["2015-07-01","2015-07-02","2015-07-03"]},{"name":"8080 Unknown","data":{"2015-07-01":4,"2015-07-02":8,"2015-07-03":5}},{"name":"8118 Unknown","data":{"2015-07-01":3}},{"name":"3389 Remote Desktop","data":{"2015-07-01":14,"2015-07-02":52,"2015-07-03":65}},{"name":"80 HTTP","data":{"2015-07-01":3,"2015-07-02":12,"2015-07-03":7}},{"name":"8228 Unknown","data":{"2015-07-01":3}}]
the problem is in data when the format is:
{"key":number,"key":number}
this should be only:
{number,number}
QUESTION: How can I remove the array keys after I sorted the occurences by date?
Upvotes: 2
Views: 59
Reputation: 126
I would probably do something along the lines of:
$headings = $result[0]['data'];
for ($i = 0; $i < count($result[1]); $i ++) {
$data = $result[1][$i]['data'];
$newdata = array();
foreach($headings as $key)
$newdata[] = isset($data[$key]) ? $data[$key] : 0;
$result[1][$i]['data'] = $newdata;
}
Upvotes: 1