0

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.

2 Answers 2

1
json_encode( array( "strings"=>array("string1", "string2", "string3" ) ) )
Sign up to request clarification or add additional context in comments.

Comments

1

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"]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.