0
I have this JSON ["{\"clube\":[\"Flamengo\"]}"]
, and when I execute that code:
$clubes = '["{\"clube\":[\"Flamengo\"]}"]';
$clubes = json_decode($clubes, true);
array_push($clubes->clube, 'Santos');
return $clubes;
I have as return this error
Attempt to modify property of non-object
I wanted to leave JSON this way ["{\"clube\":[\"Flamengo\", "Santos"]}"]
You converted clubs to array and used object notation within the push array_try
array_push($clubes['clube'], 'Santos');
– RFL
That’s what @Rafaelacioly said. You can’t access
$clubes->clube
, because you want to access a position of a array and not the ownership of an object.– user86792
Where is this json coming from?
– NoobSaibot