组合匹配多维数组键的零件,然后将另一个元素加在一起

时间:2019-07-10 04:26:49

标签: php multidimensional-array

所以我有下面的数组。我需要做的是,如果数组键[Invoice]包含相同的字符串,但后缀为A-Z,那么我需要将数组和总和[OSTotal]组合起来。如果这些行之一的[PostToGL]为N,则返回[PostoGL]为N。

如果密钥是唯一的,则按原样返回。

数组如下:

(
    [0] => Array
        (
            [Invoice] => 10000678300
            [OSTotal] => -160.0000
            [PostToGL] => Y
        )

    [1] => Array
        (
            [Invoice] => SA00031087A
            [OSTotal] => -27.5000
            [PostToGL] => N
        )

    [2] => Array
        (
            [Invoice] => SA00031087C
            [OSTotal] => 83.0000
            [PostToGL] => Y
        )

    [3] => Array
        (
            [Invoice] => SA00031087
            [OSTotal] => -26941.0700
            [PostToGL] => Y
        )

    [4] => Array
        (
            [Invoice] => SA00031087B
            [OSTotal] => -605.0000
            [PostToGL] => Y
        )

)

我需要的结果:

Array
(
    [0] => Array
        (
            [Invoice] => 10000678300
            [OSTotal] => -160.0000
            [PostToGL] => Y
        )

    [1] => Array
        (
            [Invoice] => SA00031087
            [OSTotal] => -27490.57
            [PostToGL] => N
        )

)

0 个答案:

没有答案