0

I'm encoding a very basic array like this.

$c['A']=NULL;

$c=json_encode($c);

I later want to decode the json and add a new key

$c=json_decode($c);

$c[B]=NULL;

The problem is that $c is now an object.

2 Answers 2

2

json_decode() is returning PHP Object. You need 2nd parameter if you want it to be array:

$c=json_decode($c, true);

look:http://php.net/manual/en/function.json-decode.php

When TRUE, returned objects will be converted into associative arrays.

Sign up to request clarification or add additional context in comments.

Comments

0

Use $c as an object:

$c->B = NULL;

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.