I want to build a json object with PHP.
The json object needs to be like this (for creating a google line charts):
{"cols":[{"id":"bingo","label":"bingo","type":"string"},{"id":"value","label":"value","type":"number"}],"rows":[{"c":[{"v":"date1"},{"v":151}]},{"c":[{"v":"date2"},{"v":102}]},{"c":[{"v":"date3"},{"v":52}]},{"c":[{"v":"date4"},{"v":32}]},{"c":[{"v":"date5"},{"v":7}]},{"c":[{"v":"date5"},{"v":7}]},{"c":[{"v":"date5"},{"v":7}]}]}
I have a problem creating the following part:
{"c":[{"v":"date3"},{"v":52}]},{"c":[{"v":"date4"},{"v":32}]},{"c":[{"v":"date5"},{"v":7}]},{"c":[{"v":"date5"},{"v":7}]},{"c":[{"v":"date5"},{"v":7}]}
How can I create this with PHP?
PHP comes with a JSON extension. The only thing you will need to figure out is how you have to create the data in PHP.
[]in JSON is an array,{}is a dictionary. For the part mentioned you’ll need something like this: