Reputation: 29
How to produce result like
"alpa":[{"a":"a"},{"b":"b"},{"c":"c"}]
so I can easily get them in JS.
My code currently is like this:
$arr = array();
$arr["a"] = $a;
$arr["b"] = $b;
$arr["c"] = $c;
echo json_encode($arr);
output
{"a":"a"},{"b":"b"},{"c":"c"}
Upvotes: 2
Views: 33
Reputation: 2896
Try this
$arr = array();
$arr['alpa']["a"] = $a;
$arr['alpa']["b"] = $b;
$arr['alpa']["c"] = $c;
echo json_encode($arr);
Upvotes: 1
Reputation: 7265
array(
'alpa' => array(
'a' => 'a',
'b' => 'b',
'c' => 'c',
)
);
Upvotes: 1