tags:

views:

56

answers:

1

I have this multi-dimentional array:

Array
(
    [0] => Array
        (
            [name] => lorem
            [id] => 1
            [type] => Q1
            [q1] => 39.55
            [q2] => 0

        )

    [1] => Array
        (
            [name] => lorem
            [id] => 1
            [type] => Q2
            [q1] => 0;
            [q2] => 39.55
        )

    [2] => Array
        (
            [name] => lorem
            [id] => 1
            [type] => Q1
            [q1] => 39.55
            [q2] => 39.55
        )

    [3] => Array
        (
            [owner_name] => name
            [id] => 2
            [type] => Q1
            [q1] => 39.55
        [q2] => 0
        )

)

I want to combine all the items in an array with the same id and total all the q1 and q2 in the same owner only in the same type creating a new array structure:

Array
(
    [0] => Array
        (
            [name] => lorem
            [id] => 1
        [Q1_total = > 79.1
            [q2_total] => 79.1
        )

    [1] => Array
        (
            [owner_name] => name
            [id] => 2
            [type] => Q1
            [Q1_total] => 39.55
        [Q2_total] => 0;
        )

)
A: 

You will have to use the array_map function and create a custom handler function to process your array as you want.

Sarfraz
array_map? but it applies when two array are comparing.
text
@text: no it doesn't, you should see its documentatio.
Sarfraz
I can't imagine how array_map can be implemented in that array. can you give a simple example.
text