Reputation: 6789
How do i take a php array
$arr = (('date'=>'03-22-2012', 'count'=>1000 ), ('date'=>'03-23-2011', 'count'=>1170 ));
and convert it to:
var arr = [['03-22-2012', 1000], ['03-23-2011', 1170]]
usable by a javascript function?
is there an easy way to do this?
Upvotes: 1
Views: 139
Reputation: 101811
$arr = array(
array('03-22-2012', 1000 ),
array('03-23-2011', 1170 )
);
echo "var = ".json_encode($arr).";";
Output
var = [["03-22-2012",1000],["03-23-2011",1170]];
Upvotes: 2
Reputation: 550
You are looking for json_encode: http://www.php.net/manual/en/function.json-encode.php
Only your php array definition looks a bit strange :)
Upvotes: 4