0

I have an array. After doing some condition my resulting array is as shown below.

Array
(
    [2] => Array
        (
            [OriginEventId] => 0152c945-e15b-48f9-8a0e-e4b9eace4731
            [Description] => Pension Reversion
            [transaction_date] => 2014-10-30T00:00:00
            [transaction_amount] => -1129794.96
            [member_id] => 1
            [type] => InternalTransfers
            [transaction_type] => Accumulation
        )

    [13] => Array
        (
            [OriginEventId] => 0152c945-e15b-48f9-8a0e-e4b9eace4731
            [Description] => Pension Reversion
            [transaction_date] => 2014-10-30T00:00:00
            [transaction_amount] => 1129794.96
            [member_id] => 1
            [type] => PensionsRolledBack
            [transaction_type] => Accumulation
        )

    [23] => Array
        (
            [OriginEventId] => 0152c945-e15b-48f9-8a0e-e4b9eace4731
            [Description] => Pension Reversion
            [transaction_date] => 2014-10-30T00:00:00
            [transaction_amount] => -1129794.96
            [member_id] => 1
            [type] => PensionsRolledBack
            [transaction_type] => Pension
        )

    [24] => Array
        (
            [OriginEventId] => 0152c945-e15b-48f9-8a0e-e4b9eace4731
            [Description] => Pension Reversion
            [transaction_date] => 2014-10-30T00:00:00
            [transaction_amount] => 1129794.96
            [member_id] => 2
            [type] => InternalTransfers
            [transaction_type] => Accumulation
        )

    [36] => Array
        (
            [OriginEventId] => 0152c945-e15b-48f9-8a0e-e4b9eace4731
            [Description] => Pension Reversion
            [transaction_date] => 2014-10-30T00:00:00
            [transaction_amount] => -1129794.96
            [member_id] => 2
            [type] => PensionCommencement
            [transaction_type] => Accumulation
        )

    [56] => Array
        (
            [OriginEventId] => 0152c945-e15b-48f9-8a0e-e4b9eace4731
            [Description] => Pension Reversion
            [transaction_date] => 2014-10-30T00:00:00
            [transaction_amount] => 1129794.96
            [member_id] => 2
            [type] => PensionCommencement
            [transaction_type] => Pension
        )

)

My job is to remove any offsetting transactions. For example: If one member's accumulation has a positive and negative, then remove them.

By using this resultant array, I need to filter based on member_id, transaction_type and transaction_amount. (it may be positive or negative). If member_id and transaction_type are same then I need to remove the offsetting transaction.

After removal, the resulting array must look like this:

Array
(
   [23] => Array
        (
            [OriginEventId] => 0152c945-e15b-48f9-8a0e-e4b9eace4731
            [Description] => Pension Reversion
            [transaction_date] => 2014-10-30T00:00:00
            [transaction_amount] => -1129794.96
            [member_id] => 1
            [type] => PensionsRolledBack
            [transaction_type] => Pension
        )

   [56] => Array
       (
           [OriginEventId] => 0152c945-e15b-48f9-8a0e-e4b9eace4731
           [Description] => Pension Reversion
           [transaction_date] => 2014-10-30T00:00:00
           [transaction_amount] => 1129794.96
           [member_id] => 2
           [type] => PensionCommencement
          [transaction_type] => Pension
     )
)
roberrrt-s
  • 7,914
  • 2
  • 46
  • 57
  • use `abs()` to change a negative number to positive, then compare them. – Xorifelse Nov 29 '16 at 07:34
  • How to do multiple search without using multiple loops –  Nov 29 '16 at 07:40
  • What do you have so far and where are you stuck specifically? – jeroen Nov 29 '16 at 07:41
  • by using array search i retrieved above above array. Now i need to multiple search i stuck in it –  Nov 29 '16 at 07:44
  • Please take a look at this solution: http://stackoverflow.com/questions/8102221/php-multidimensional-array-searching-find-key-by-specific-value/21317079#21317079 Hope, you'll find useful. – Fatalist Feb 17 '17 at 19:06

0 Answers0