I have an array like below which is generated by parsing a xml url.
The array is
JavaScript
x
Array
(
[Tags] => SimpleXMLElement Object
(
[0] =>
)
)
The array name is $result
. Now I want to check that if the array received like above I want to print a message of failure. But how to check this array in if condition?
Advertisement
Answer
you can use
JavaScript
empty($result)
to check if the main array is empty or not.
But since you have a SimpleXMLElement object, you need to query the object if it is empty or not. See http://www.php.net/manual/en/simplexmlelement.count.php
ex:
JavaScript
if (empty($result) || !isset($result['Tags'])) {
return false;
}
if ( !($result['Tags'] instanceof SimpleXMLElement)) {
return false;
}
return ($result['Tags']->count());