开发者

Cant Set::extract() from a data structure

开发者 https://www.devze.com 2023-02-27 15:27 出处:网络
I have a data structure that looks like the one below (only larger, this is a snippet). I\'m trying to generate a sum of all TechnologyIncentive amount values that are provided in USD format. Set::ext

I have a data structure that looks like the one below (only larger, this is a snippet). I'm trying to generate a sum of all TechnologyIncentive amount values that are provided in USD format. Set::extract seems like a natural way of doing this quickly and easily, but I'll be damned if I can get this to do what I think it should do. I know Set::extract only supports an XPath subset, but I'm working within that context, I think. I've tried

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  )

The $group value evaluates to "Appliances" or "Building Shell" in the structure below. Other groups exist in the non-abridged version of the data structure. I could understand it getting confused by the space in "Building Shell", but it doesn't even work for "Appliances". I'm hoping I just have something wrong that I've lost the ability to see.

The idea is to get an array of values and then throw array_sum() at it to get the total values for each group.

Thanks for your help. The data structure I'm working against follows...

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-开发者_Python百科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
              )
          )
    )
)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号