I'm asking for explanation of the following behavior behind the scene in PHP.
I have a SimpleXMLElement Object that I print_r(); Here is the result:
Array
(
[Shipments] => SimpleXMLElement Object
(
[Shipment] => SimpleXMLElement Object
(
[Rates] => SimpleXMLElement Object
(
[Rate] => SimpleXMLElement Object
(
[Service] => C
[ServiceCharge] => 10.18
[ServiceChargeDetails] => SimpleXMLElement Object
(
[BaseCharge] => 8.33
[CODCharge] => 0
[DeclaredCharge] => 0
[AdditionalCharges] => 1.85
[SaturdayCharge] => 0
)
[FuelCharge] => 0
[TotalCharge] => 10.18
[BilledWeight] => 6
[TransitDays] => 1
[ExpectedDeliveryDate] => 20160121
[CommitTime] => 17:00:00
[RateZone] => 2
[GlobalRate] => 10.66
)
)
[UID] => ID1
[Delzip] => 95126
[PUZip] => 95035
[Declared] => 100
[Residential] => true
[COD] => 0
[SaturdayDel] => false
[Weight] => 2
[DIM] => SimpleXMLElement Object
(
[Length] => 10
[Width] => 12
[Height] => 13
)
[Error] => SimpleXMLElement Object
(
)
)
[Error] => SimpleXMLElement Object
(
)
)
)
Please take a look at the "TotalCharge". It doesn't seem to have any child elements however when I do the following:
print_r($response['Shipments']->Shipment->Rates->Rate->TotalCharge);
Here is what I get:
SimpleXMLElement Object
(
[0] => 10.18
)
I'm trying to understand how did the [0] get there and why the initial print_r didn't show it?
Thanks!