Reputation: 37
I have an object and like to retrieve the value of one or more elements from the object. Hire is one of the objects if put in a var_dump().
object(SimpleXMLElement)#13 (2) {
["@attributes"]=>
array(1) {
["name"]=>
string(5) "chain"
}
["value"]=>
string(11) "Abba Hotels"
}
I get the value but i can not get to the name.
To get the value i use for example:
echo $row->property->value
My first thought was to use:
echo $row->property->@attributes->name
, but it return as a ERROR. I try to use @attributes in a variable but that gives a NULL.
At second thought i tried to use get_object_vars() and in_array() but no luck again.
Do you guys have a idea about how i can get to the value of the "name" object?
Upvotes: 0
Views: 243
Reputation: 1394
It looks like you are using a property value from somewhere. If $row is the object, then you could use this I think.
$row->@attritubes['name']
Im not fully sure but thought id give it a go helping anyawy. Let me know if it works.
Upvotes: 0
Reputation: 22656
See the docs for SimpleXMLElement:
$object->attributes()
Will give you what you need. I.e.
echo $object->attributes()->name;
Upvotes: 1