Reputation: 545
I'm using the json_encode function to transform a php array to a json. Now, i want to generate something like this :
"Strings": ["String 1","String 2","String 3"]
I don't know how to do ?
I tried :
$array["strings"] = '["String 1","String 2","String 3"]';
But it doesn't work as i get this as result :
"Strings":"[\"String 1\", \"String 2\", \"String 3\"]"
Then i tried this
$array["strings"] = '[String 1,String 2,String 3]';
It doesn't work, i got this as result :
"Strings":"[String 1, String 2, String 3]"
Can someone help me please ?
Thx.
Upvotes: 0
Views: 61
Reputation: 6087
json_encode( array( "strings"=>array("string1", "string2", "string3" ) ) )
Upvotes: 1
Reputation: 31
You have to define it like this
$array["String"] = ["String 1","String 2","String 3"];
then you output will be:
"String":["String 1","String 2","String 3"]
Upvotes: 1