Search code examples
phparraysvar-dump

Cant get value in PHP array but var_dump shows that it exists


Long time, my PHP-application ran on a linux server with apache and PHP.

Now I've set up a windows server with apache and php and simple PHP-Programs have problems.

var_dump($data);
die(var_dump($data['a']));

results in

object(stdClass)#1 (1) { ["a"]=> string(1) "b" } 
Fatal error: Cannot use object of type stdClass as array in BLUB.php on line 14

var_dump says there is an index a. Why does $data['a'] throw an exception?

EDIT: $data is json_decode($something);


Solution

  • You should use:

     $data = json_decode($something, true);
    

    To get array from json