<?php
$json = '[
{
"StatsHistoryTime": "2019-02-06 12:00:00",
"name": "shelly",
"hashrate": 2147483647
},
{
"StatsHistoryTime": "2019-02-06 12:00:00",
"name": "debra",
"hashrate": 1240996571
},
{
"StatsHistoryTime": "2019-02-06 12:00:00",
"name": "sally",
"hashrate": 2147483647
},
{
"StatsHistoryTime": "2019-02-06 12:00:00",
"name": "bill",
"hashrate": 2147483647
},
{
"StatsHistoryTime": "2019-02-06 12:30:00",
"name": "shelly",
"hashrate": 2147483647
},
{
"StatsHistoryTime": "2019-02-06 12:30:00",
"name": "debra",
"hashrate": 1460613388
},
{
"StatsHistoryTime": "2019-02-06 12:30:00",
"name": "sally",
"hashrate": 2147483647
},
{
"StatsHistoryTime": "2019-02-06 12:30:00",
"name": "bill",
"hashrate": 2147483647
}
]';
$rows = json_decode($json, true);
$chartdata = array();
foreach ($rows as $row) {
$period = $row['StatsHistoryTime'];
if (($k = array_search($period, array_column($chartdata, 'period'))) !== false) {
$chartdata[$k][$row['name']] = $row['hashrate'];
}
else {
$chartdata[] = array('period' => $period, $row['name'] => $row['hashrate']);
}
}
echo json_encode($chartdata);
preferences:
26.48 ms | 407 KiB | 5 Q