Reputation: 468
I cant seem to get my json_encode to include brackets.. Any help?
My code is:
$th = json_encode(array("4" => "four", "8" => "eight"));
echo $th;
and the output is:
{"4":"four","8":"eight","9":"\n"}
The output I need to send to the api is:
[{"4":"four","8":"eight","9":"\n"}]
How can I get the brackets in the JSON array? Thank you!
Upvotes: 0
Views: 153
Reputation: 1548
Use this
$th = json_encode(array(array("4" => "four", "8" => "eight", "9" => "\n")));
Upvotes: 0
Reputation: 3506
You should do this way:
$th = json_encode(array(array("4" => "four", "8" => "eight")));
Upvotes: 3