Skip to content
Advertisement

Getting a specific value from a json response

I have this code

JavaScript

which produces there

JavaScript

My question is how do I get the value of name and account_rep I tried

JavaScript

but that does not work it just throws an error

JavaScript

Advertisement

Answer

json_decode($variable), is used to decode or convert a JSON object to a PHP object.

So you could do this as $client['0'] is an object.

JavaScript

But I’d say you should rather convert the json object to associative array instead of PHP object by passing TRUE to as an argument to the json_decode. When TRUE, returned objects get converted into associative arrays.

JavaScript

Now $client is

JavaScript

Now you could simply do

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement