出力(print_r)の配列があります:
Array
(
[a] => 706
[b] => 194
[c] => 164
[d] => 44
[e] => 42
[f] => 41
[g] => 40
[h] => 38
[i] => 13
)
これを次の形式の json に変換する必要があります。
[{"name":"a","value":706},{"name":"b","value":194},{"name":"c","value":164},{"name":"d","value":44},{"name":"e","value":42},{"name":"f","value":41},{"name":"g","value":40},{"name":"h","value":38},{"name":"i","value":13}]
これは私が試したものですが、推測しているだけで、正しい出力が得られません:
echo '[';
foreach($sortedArray as $key => $value) {
echo $dataTable = json_encode(array(
'name' => $key,
'value' => $value
), JSON_NUMERIC_CHECK);
};
echo ']';