3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
232.01 ms | 2161 KiB | 12 Q