I want to be able to look for and alter specific properties that may or may not exist in a given object. These properties are part of an inconsistently structured array, so I want to define ahead of time what properties to look for.
$properties = array(
"color",
"name['first']",
"jobs->primary['company']",
"location['home']['city']",
etc...
);
foreach ($properties as $property) {
if (isset($some_object->$property)) {
...
}
}
The problem is, of course, with '$some_object->$property' which is always null.
I assume $property is being treated as a string rather than a variable name. I just don't recall if there's way to indicate that it's part of the variable name and not a simple string.
Thanks!
"location['home']['city']", do you expect to get$some_object->location['home']['city'], or$some_object->{"location['home']['city']"}?