Answer the question
In order to leave comments, you need to log in
How to build JSON suitable for dxChart.js?
There is such a library dxChart.js, it is needed to build various charts and graphs, it takes the following JSON as an argument:
[
{ year: 2005, value: 2450 },
{ year: 2006, value: 2156 },
{ year: 2014, value : 3650 }
]
There is a php script that generates JSON for Ajax:
$words - an array with words;
$count - an array with the number of repetitions of the word;
The length of $words and $count is the same
How to generate JSON like this in a for or foreach loop:
[
{"word": "word", count: 12},
{"word": "word two", count: "14"},
{"word": "wordN", count: "some value"}
]
Answer the question
In order to leave comments, you need to log in
$results = [];
foreach ($something as $x) {
$results[] = $x;
}
echo json_encode($results);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question