How to check the value of a simplexml object

I have an array that is a simple xml object. I write codes below

Array ( [ID] => 1992109 [Title] => A Equipa do MAIS [Description] => SimpleXMLElement Object ( ) ) 

Now, how can I check the Description value in this array if there is a Description value present or not.

+4
source share
1 answer

To check if a SimpleXMLElement object SimpleXMLElement text value, you need to specify it as a string:

 $desc = (string)$array['Description']; if (!empty($desc)) { echo $desc; } 

Although you can directly echo contents of the SimpleXMLElement object, using its string value as a variable requires matching it. empty() should act on variable 1 so calling the __toString() implicit element will not work the same as with echo .


1 Starting with PHP 5.5, empty() can test an arbitrary result of an expression. This no longer requires a variable as an argument.

+8
source

Source: https://habr.com/ru/post/1380502/


All Articles