我有一个看起来像下面的数据结构(只有更大,这是一个片段)。我正在尝试生成以USD格式提供的所有TechnologyIncentive
金额值的总和。 Set::extract
似乎是一种快速轻松地做到这一点的自然方式,但如果我能做到这一点,我会被诅咒,我认为应该这样做。我知道Set::extract
只支持XPath子集,但我认为我在这种情况下工作。我试过了
Set::extract( '/' . $group . '/IncentiveAmountType[incentive_amount_type_id=USD]/../TechnologyIncentive/amount', $incentives )
Set::extract( '/' . $group . '/{n}/IncentiveAmountType[incentive_amount_type_id=USD]/../TechnologyIncentive/amount', $incentives )
$group
值在下面的结构中评估为“Appliances”或“Building Shell”。其他组存在于数据结构的非删节版本中。我可以理解它被“建筑外壳”中的空间搞糊涂了,但它甚至不适用于“家电”。我希望我有一些错误,我已经失去了看见的能力。
我们的想法是获取一组值,然后向其中抛出array_sum()
以获取每个组的总值。
感谢您的帮助。我正在努力解决的数据结构如下......
Array
(
[Appliances] => Array
(
[875] => Array
(
[TechnologyIncentive] => Array
(
[id] => 875
[incentive_id] => ccf4ceb8-6538-11e0-9cbb-00259028905a
[technology_id] => d4da5c6a-6538-11e0-9cbb-00259028905a
[amount] => 75.00
[incentive_amount_type_id] => 0fb78496-6ad6-11e0-9cbb-00259028905a
[is_active] => 1
)
[IncentiveAmountType] => Array
(
[id] => 0fb78496-6ad6-11e0-9cbb-00259028905a
[incentive_amount_type_id] => USD
[name] => $
[description] => US Dollars
[version] => 0
[display] => 1
)
)
[1103] => Array
(
[TechnologyIncentive] => Array
(
[id] => 1103
[incentive_id] => ccf4c9b8-6538-11e0-9cbb-00259028905a
[technology_id] => d4da5c6a-6538-11e0-9cbb-00259028905a
[amount] => 50.00
[incentive_amount_type_id] => 0fb78496-6ad6-11e0-9cbb-00259028905a
[is_active] => 1
)
[IncentiveAmountType] => Array
(
[id] => 0fb78496-6ad6-11e0-9cbb-00259028905a
[incentive_amount_type_id] => USD
[name] => $
[description] => US Dollars
[version] => 0
[display] => 1
)
)
)
[Building Shell] => Array
(
[1110] => Array
(
[TechnologyIncentive] => Array
(
[id] => 1110
[incentive_id] => ccf4c9b8-6538-11e0-9cbb-00259028905a
[technology_id] => d4d9b79c-6538-11e0-9cbb-00259028905a
[amount] => 150.00
[incentive_amount_type_id] => 0fb78496-6ad6-11e0-9cbb-00259028905a
[is_active] => 1
)
[IncentiveAmountType] => Array
(
[id] => 0fb78496-6ad6-11e0-9cbb-00259028905a
[incentive_amount_type_id] => USD
[name] => $
[description] => US Dollars
[version] => 0
[display] => 1
)
)
[10941] => Array
(
[TechnologyIncentive] => Array
(
[id] => 10941
[incentive_id] => ccf4ceb8-6538-11e0-9cbb-00259028905a
[technology_id] => d4d9b79c-6538-11e0-9cbb-00259028905a
[amount] => 40.00
[incentive_amount_type_id] => 0fb783c4-6ad6-11e0-9cbb-00259028905a
[is_active] => 1
)
[IncentiveAmountType] => Array
(
[id] => 0fb783c4-6ad6-11e0-9cbb-00259028905a
[incentive_amount_type_id] => PERC
[name] => %
[description] => Percent
[version] => 0
[display] => 1
)
)
)
)