stdClass Object ([Sector] => Manufacturing [Date Found] => 2010-05-03 08:15:19)
So I can access [Sector]
by using $object->Sector
but how can I access [Date Found]
?
Use bracket notation to access a key that contains a space in an object, e.g. obj['my key'] . The bracket [] notation syntax allows us to access an object's key, even if it contains spaces, hyphens or special characters.
Object Keys Are Strings Object keys with underscores and camelCase (no spaces) don't require the bracket syntax, but object keys with spaces and hyphens do. You may prefer the code readability of the . dot syntax, in which case you'll want to avoid spaces in your object keys: you might write object.
Note: A property declared without a Visibility modifier will be declared as public . Within class methods non-static properties may be accessed by using -> (Object Operator): $this->property (where property is the name of the property). Static properties are accessed by using the :: (Double Colon): self::$property .
You can do it this way:
$object->{'Date Found'}
have you tried
$property = 'Date Found'; $object->{$property};
Or simply
$object->{'Date Found'};
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