I try to check if SimpleXml element is an array.
I saw the given examples here on PHP doc and so it seems possible to check if a node is an array. But in my case, I cannot do it.
A var_dump($myElement)
gives me:
object(SimpleXMLElement)#701 (4) {
["@attributes"]=> array(1) {
["id"]=> string(7) "5831377"
}
["openPeriod"]=> string(10) "2016-04-01"
["closePeriod"]=> string(10) "2016-05-31"
["periods"]=> object(SimpleXMLElement)#703 (1) {
["period"]=> array(2) {
[0]=> object(SimpleXMLElement)#707 (3) {
["startPeriod"]=> string(8) "10:00:00"
["endPeriod"]=> string(8) "12:30:00"
["weekDays"]=> string(51) "monday,tuesday,wednesday,thursday,friday,saturday,sunday"
}
[1]=> object(SimpleXMLElement)#702 (3) {
["startPeriod"]=> string(8) "14:00:00"
["endPeriod"]=> string(8) "20:00:00"
["weekDays"]=> string(51) "monday,tuesday,wednesday,thursday,friday,saturday,sunday"
}
}
}
}
Depending $myElement
, $myElement->periods->period
could be an object or an array.
But in the given case, debug(is_array($myElement->periods->period))
returns false
.
Could you tell me why?
EDIT
Here is the original XML element:
<openingPeriod id="5831487">
<openPeriod>2016-04-01</openPeriod>
<closePeriod>2016-05-31</closePeriod>
<periods>
<period>
<startPeriod>10:00:00</startPeriod>
<endPeriod>12:30:00</endPeriod>
<weekDays>monday,tuesday,wednesday,thursday,friday,saturday,sunday</weekDays>
</period>
<period>
<startPeriod>14:00:00</startPeriod>
<endPeriod>20:00:00</endPeriod>
<weekDays>monday,tuesday,wednesday,thursday,friday,saturday,sunday</weekDays>
</period>
</periods>
</openingPeriod>