I got something that's really got me stumped that I was hoping somebody could help me figure out here...
How can you add XML node values together from two or more different XML elements if a separate node in the same element matched the value of that node in the last element?
So in the example below, if <promo> equals 1122 in more than one element, it will add both <amount> from both of those nodes together?
$result = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($result);
foreach ($xml->orderData as $record)
{
if ($record->promo == next($record->promo)) {
$amount = $record->accountAmount + $amount;
} else {
$amount = $record->accountAmount;
}
}
example of the xml data:
<orderData>
<promo>1121</promo>
<amount>25.00</amount>
</orderData>
<orderData>
<promo>1122</promo>
<amount>25.00</amount>
</orderData>
<orderData>
<promo>1122</promo>
<amount>45.00</amount>
</orderData>
<orderData>
<promo>1123</promo>
<amount>25.00</amount>
</orderData>
It's got me stumped pretty good! I don't think next() will work in this case though 🙁