Answer the question
In order to leave comments, you need to log in
How should the json look like for the given php code?
Hello, I spent 40 minutes on how json should look like for this code, but I still don’t understand, please help
<?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" : ''));
?>
Answer the question
In order to leave comments, you need to log in
Something like this...
<?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);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question