After json_decode I have this array. How to turn on the key and get the value?

stdClass Object ( [$] => on ) 

  • one
    $data->{'$'} ? - teran
  • Thank! This is the right answer! - Pavel Zhukovsky
  • posted a response - teran

1 answer 1

For access to fields of objects that have spaces, hyphens, etc. in the title. characters not satisfying the naming of variables and fields use the syntax $object->{'my-field name'} :

 $json = '{ "$": 123, "test": 2343 }'; $data = json_decode($json); print_r([ $data->{'$'} ]);