我在这里看到了类似的问题,但我似乎无法将解决方案应用于我的问题。我有一个名为 $results 的变量,它是从 API 获得的。我将更改专有名词以保护我工作的客户:
stdClass Object
(
[out] => stdClass Object
(
[count] => 2
[transactions] => stdClass Object
(
[RealTimeCommissionDataV2] => Array
(
[0] => stdClass Object
(
[adId] => 12345678
[advertiserId] => 123456789
[advertiserName] => Chuck E. Cheese, inc.
[commissionAmount] => 50
[country] => US
[details] => stdClass Object
(
)
[eventDate] => 2009-11-16T09:44:25-08:00
[orderId] => X-XXXXXXXXXX
[saleAmount] => 0
[sid] => 123456789
[websiteId] => 2211944
)
[1] => stdClass Object
(
[adId] => 987654321
[advertiserId] => 12345
[advertiserName] => Chorizon Wireless.
[commissionAmount] => 50
[country] => US
[details] => stdClass Object
(
)
[eventDate] => 2009-11-16T09:58:40-08:00
[orderId] => X-CXXXXXX
[saleAmount] => 0
[sid] => 61-122112
[websiteId] => 1111922
)
)
)
)
)
我在这里将其缩短为两个条目,但条目的数量会有所不同,这是过去一小时内检查交易的结果,有时可能只有一个,有时可能多达十几个。
我想将这些条目分配给 websiteId1 websiteId2 等变量。我知道我需要做一个 foreach 循环,但似乎无法弄清楚。如何编写它以便我也得到“[详细信息]”?