i have an array that is simple xml object. i am writing the codes below
Array
(
[ID] => 1992109
[Title] => A Equipa do MAIS
[Description] => SimpleXMLElement Object
(
)
)
now how can i check the value of Description in this array that if there is a value of Description is present or not.
To verify if a SimpleXMLElement
object has a text value, you'll need to cast it as a string:
$desc = (string)$array['Description'];
if (!empty($desc)) {
echo $desc;
}
Although you are able to directly echo
the contents of a SimpleXMLElement
object, to use its string value as a variable requires typecasting it. empty()
must act on a variable1, so the element's implicit __toString()
call won't work as it does with echo
.
1Beginning with PHP 5.5, empty()
can test an arbitrary expression's result. It no longer requires a variable as its argument.
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