I have a variable $entry which is set to:
stdClass Object ( [im:name] => stdClass Object ( [label] => Amazing Breaker ) etc.
How can I access the value "Amazing Breaker"?
I tried to define a constant:
define("IMNAME", 'im:name');
but using:
foreach ($json_output->feed->entry as $entry) {
if (isset($entry->IMNAME->label))
returns FALSE.
Problem seems to be the colon. For a key without colon the code would return TRUE.
In PHP, the double colon :: is defined as Scope Resolution Operator. It used when when we want to access constants, properties and methods defined at class level. When referring to these items outside class definition, name of class is used along with scope resolution operator.
=> is the separator for associative arrays. In the context of that foreach loop, it assigns the key of the array to $user and the value to $pass .
@property shows a "magic" property variable that is found inside the class. datatype should be a valid PHP type or "mixed." phpDocumentor will display the optional description unmodified, and defaults to "mixed" if the datatype is not present.
This is referred to as the object operator, or sometimes the single arrow operator. It is an access operator used for access/call methods and properties in a PHP object in Object-Oriented Programming (OOP). Example.
You can use the free-form syntax with curly braces for 'special' property names:
if (isset($entry->{'im:name'}->label))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With