<?php
$json = <какой то json>;
$mapstats = json_decode($json, true);
$totalUsed = 0;
foreach ($mapstats as $i)
$totalUsed += $i['usageCount'];
foreach ($mapstats as $key => $value)
echo('{ name: \'' . $mapstats[$key]['map'] . '\', y: ' . str_replace(',','.',($mapstats[$key]['usageCount'] / $totalUsed) * 100) . ' }' . (($key != (count($mapstats) - 1)) ? ",\n" : ''));
?>
<?php
$json = <какой то json>;
$mapstats = json_decode($json, true);
$totalUsed = 0;
foreach ($mapstats as $i) {
$totalUsed += $i['usageCount'];
}
$data = [];
foreach ($mapstats as $value) {
$data[] = [
"name" => $value["map"],
"y" => $value["usageCount"] / $totalCount * 100
];
}
echo json_encode($data);