M
M
Michael Kim2015-11-09 23:56:32
JSON
Michael Kim, 2015-11-09 23:56:32

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

1 answer(s)
S
Stalker_RED, 2015-11-10
@Marox

$results = [];
foreach ($something as $x) {
   $results[] = $x;
}
echo json_encode($results);

Where $x is an array like ['word'=>'abc', 'count'=>7]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question