-2
I’m trying to go through the transaction of the following array but without success:
Array
(
[date] => 2021-08-07T20:48:14.000-03:00
[transactions] => Array
(
[transaction] => Array
(
[date] => 2021-08-07T19:14:44.000-03:00
[reference] => TPW-253961
[code] => 3ECE880C-AEFF-4A3E-44E5
[type] => 1
[status] => 4
[paymentMethod] => Array
(
[type] => 11
)
[grossAmount] => 3.00
[discountAmount] => 0.00
[feeAmount] => 0.06
[netAmount] => 2.94
[extraAmount] => 0.00
[lastEventDate] => 2021-08-07T19:15:59.000-03:00
)
[transaction] => Array
(
[date] => 2021-08-07T19:15:44.000-03:00
[reference] => TPW-253961
[code] => 3ECE880C-AEFF-4A3E-99EA
[type] => 1
[status] => 4
[paymentMethod] => Array
(
[type] => 11
)
[grossAmount] => 3.00
[discountAmount] => 0.00
[feeAmount] => 0.06
[netAmount] => 2.94
[extraAmount] => 0.00
[lastEventDate] => 2021-08-07T19:15:59.000-03:00
)
)
[resultsInThisPage] => 1
[currentPage] => 1
[totalPages] => 1
)
The array is originally received from an XML, so I am converting as follows to PHP:
$xml = simplexml_load_string($response, "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_encode($xml);
$array = json_decode($json,true);
And with the following foreach I’m trying to show off the status and code of each transaction:
foreach ($array["transactions"]["transaction"] as $resultado){
echo $resultado["status"].' - '.$resultado["code"].'<br>';
}
The result of echo is something completely different than expected, besides not returning the status and code of each transaction, there are 12 result lines (one for each item in the transaction array: