I have a SimpleXMLElement and would like to check if a particular element has a non-blank value before looping through it utilizing a foreach loop. Here is my SimpleXMLObject
Say this is contained in $myXMLElement
SimpleXMLElement Object ( [f] => Array ( [0] => Marcus [1] => Smith [2] => Brown University [3] => 1243123200000 [4] => Masters [5] => TestValue [6] => TestValue2 [7] => 4 [8] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 16 ) ) [9] => 0 ) [update_id] => 1325795135203 )
Within the array is a value of
[3] => 1243123200000
This is what I would like to check this parameter and determine that it is not NULL. If I wanted to grab it as a String what would be the way to do this.
I was hoping for something like (string)$myXMLElement[3] but that does not appear to be correct syntax for what I am trying.
You can use array notation, but since the array is part of the node
fyou have to access it like this:On an unrelated note, since the 8th element in that array is itself a SimpleXML object, you would access its values like this:
In these cases, its just a mix of object access and array access notation.
To get the attributes from the 8th element, you can also use array notation:
The page on Basic SimpleXML Usage has some very helpful examples showing how to access different elements from a SimpleXML object. Example #5 show how to access attributes.