user2321895
user2321895

Reputation: 87

PHP: json_decode assoc array not displaying value

After a json_decode this is the var_dump of the assoc array:

array(1) { 
    [0]=> array(8) { 
        ["Username"]=> string(11) "test" 
        ["FirstName"]=> string(6) "Test1" 
        ["LastName"]=> string(5) "Test2" 
        ["Gender"]=> string(6) "Male" 
     }
}

if try to echo $array["FirstName"] it doesn't display anything, I've tried everything and nothing works.

Upvotes: 0

Views: 155

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324740

That's because there is no such key as FirstName on the main array. However, there is one on the inner array.

echo $array[0]['FirstName'];

Note that if you had enabled show_errors and had suitable error_reporting set, you would have seen a Notice-level error informing you of the problem.

Upvotes: 2

Related Questions