I'm trying to get some info out of a decoded JSon string into an array.
I've this code:
$json_d='{ // This is just an example, I normally get this from a request...
"iklive.com":{"status":"regthroughothers","classkey":"domcno"}
}';
$json_a=json_decode($json_d,true);
$full_domain = $domain.$tlds; // $domain = 'iklive' ; $tlds = '.com'
echo $json_a[$full_domain][status];
The problem is, I need to get the value for "status" of "iklive.com" but when I do echo $json_a[$full_domain][status];
it does not work, but if I do it manually like echo $json_a['iklive.com'][status];
(with the quotes there) it works.
I've tried to add the quotes to the variable but without success, how can I do this?
Thanks Everyone!
Thanks to Pekka and jeromegamez I noticed a error in the HTML part of this "problem", the $tlds
variable was "com" instead of ".com" -- Sorry by wasting your time with this. I do feel bad now.
Anyway, thanks to jeromegamez and Marc B I discovered that unless status
was a constant I need to quote it ;) You can check jeromegamez answer to a detailed explanation of the problem and proper debug.
Sorry.
$full_domain
is? – Brad Nov 3 '11 at 21:04$full_domain='iklive.com'
? – ComFreek Nov 3 '11 at 21:04$full_domain
has that value? Then there shouldn't be a problem. Are you keeping in mind that array indexes are case sensitive? – Pekka 웃 Nov 3 '11 at 21:04status
hasn't been quoted. Unless you've got astatus
constant define()'d, a PHP install in strict mode should gripe about both versions. – Marc B Nov 3 '11 at 21:04