I have a array, it changes value every time when new data come (it's not from database). I want to calculate key 1 and key 2 value if the key 1 and key 3 matched even there is 5 arrays it returns value in one, but i am confused how to do that, here is the array I have:
Array
(
[0] => Array
(
[0] => root
[1] => 0.0
[2] => 4428
[3] => sshd
)
[1] => Array
(
[0] => root
[1] => 12.5
[2] => 1192
[3] => sshd
)
[2] => Array
(
[0] => root
[1] => 0.0
[2] => 908
[3] => udevd
)
[3] => Array
(
[0] => root
[1] => 7
[2] => 776
[3] => udevd
)
[4] => Array
(
[0] => root
[1] => 0.0
[2] => 592
[3] => mingetty
)
[5] => Array
(
[0] => root
[1] => 2
[2] => 592
[3] => mingetty
)
[6] => Array
(
[0] => root
[1] => 0.0
[2] => 588
[3] => mingetty
)
[7] => Array
(
[0] => root
[1] => 0.0
[2] => 0
[3] => migration/0
)
[8] => Array
(
[0] => ntd
[1] => 0.0
[2] => 0
[3] => ksoftirqd/0
)
[9] => Array
(
[0] => root
[1] => 0.0
[2] => 0
[3] => ksoftirqd/0
)
}
I need an output like this:
Array
(
[0] => Array
(
[0] => root
[1] => 12.5
[2] => 5620
[3] => sshd
)
[1] => Array
(
[0] => root
[1] => 7
[2] => 1684
[3] => udevd
)
[2] => Array
(
[0] => root
[1] => 2
[2] => 1772
[3] => mingetty
)
[3] => Array
(
[0] => root
[1] => 0.0
[2] => 0
[3] => migration/0
)
[4] => Array
(
[0] => ntd
[1] => 0.0
[2] => 0
[3] => ksoftirqd/0
)
[5] => Array
(
[0] => root
[1] => 0.0
[2] => 0
[3] => ksoftirqd/0
)
}
In detail:
I need to make a script/code to match all the array using key 0 and key 3 and both must be matched inside array.
Then we have to sum up key 1 value with all the others found array key 1 and key 2 value with all the others found key 2.
I hope I explain it clearly, I need a solution if possible don't post code just give me a guide how it's done.
I try different things which I think should work but I terribly fail.