我有一个从XML转换后得到的数组,这个XML来自亚马逊卖家帐户。它已获得我的卖家帐户中提供的所有订单。
我正在使用Yii 2.0 php框架,我在将XML转换为控制器中的数组后将此数组传递给视图。这是我的阵列..
Array
(
[ListOrdersResult] => Array
(
[CreatedBefore] => 2016-07-11T05:59:05Z
[Orders] => Array
(
[Order] => Array
(
[0] => Array
(
[AmazonOrderId] => 171-4557760-7388350
[PurchaseDate] => 2016-06-01T13:07:46Z
[LastUpdateDate] => 2016-06-03T12:43:26Z
[OrderStatus] => Canceled
[FulfillmentChannel] => MFN
[SalesChannel] => Amazon.in
[ShipServiceLevel] => IN Exp Dom 2
[OrderTotal] => Array
(
[CurrencyCode] => INR
[Amount] => 40.00
)
[NumberOfItemsShipped] => 0
[NumberOfItemsUnshipped] => 0
[PaymentExecutionDetail] => Array
(
)
[MarketplaceId] => A21TJRUUN4KGV
[ShipmentServiceLevelCategory] => Expedited
[ShippedByAmazonTFM] => false
[OrderType] => StandardOrder
[EarliestShipDate] => 2016-06-01T18:30:00Z
[LatestShipDate] => 2016-06-03T18:29:59Z
[IsPrime] => false
[IsPremiumOrder] => false
)
[1] => Array
(
[AmazonOrderId] => 403-4718683-0373128
[PurchaseDate] => 2016-06-03T12:30:20Z
[LastUpdateDate] => 2016-06-03T14:02:13Z
[OrderStatus] => Canceled
[FulfillmentChannel] => MFN
[SalesChannel] => Amazon.in
[ShipServiceLevel] => IN Exp Dom 2
[OrderTotal] => Array
(
[CurrencyCode] => INR
[Amount] => 40.00
)
[NumberOfItemsShipped] => 0
[NumberOfItemsUnshipped] => 0
[PaymentExecutionDetail] => Array
(
)
[MarketplaceId] => A21TJRUUN4KGV
[ShipmentServiceLevelCategory] => Expedited
[ShippedByAmazonTFM] => false
[OrderType] => StandardOrder
[EarliestShipDate] => 2016-06-03T18:30:00Z
[LatestShipDate] => 2016-06-06T18:29:59Z
[IsPrime] => false
[IsPremiumOrder] => false
)
)
)
)
[ResponseMetadata] => Array
(
[RequestId] => 42c3353b-d6af-459f-9421-5e8b7efb8ea8
)
)
这里每个数组都是订单,现在我想逐个显示..任何人都可以帮助我如何显示..我正在使用Yii2 Php框架进行这个项目...谢谢..
答案 0 :(得分:1)
它应该是这样的:
$myArray['ListOrdersResult']['Orders']['Order'][0]['AmazonOrderId'] = '171-4557760-7388350';
function print_order($order) {
foreach ($order as $key1=>$val) {
if (is_array($val))
print_order($val);
else
print "$key1 = $val<br/>\r\n";
}
}
print_order($myArray['ListOrdersResult']['Orders']['Order']);