Reputation: 26281
I am using http://www.jqplot.com/tests/pie-donut-charts.php which needs to have data given to it in the following format:
//JavaScript
var data = [
['Heavy Industry', 12],['Retail', 9], ['Light Industry', 14],
['Out of home', 16],['Commuting', 7], ['Orientation', 9]
];
The data is generated serverside with PHP. I am manually creating the string as follows:
//PHP
$string.='["'.$row['name'].'",'.$row['count'].'],';
I would rather just create an array, and use json_encode() or something similar to create the data. Any suggestions how I would do so?
Upvotes: 0
Views: 740
Reputation: 11467
$array = array(
array(
"Heavy Industry",
12
),
array(
"Retail",
9
)
);
$json = json_encode($array);
var_dump($json); // "[["Heavy Industry",12],["Retail",9]]"
Upvotes: 1