I got a multidimensional array like this:
Totalarray
(
[0] => Array
(
[city] => NewYork
[cash] => 1000
)
[1] => Array
(
[city] => Philadelphia
[cash] => 2300
)
[2] => Array
(
[city] => NewYork
[cash] => 2000
)
)
and I'd like to sum the value [cash] of the sub-arrays who got the same value[city] and obtain an array like this:
Totalarray
(
[0] => Array
(
[city] => NewYork
[cash] => 3000
)
[1] => Array
(
[city] => Philadelphia
[cash] => 2300
)
)
How can I do it?
Try below code:
Output:
Demo:
http://3v4l.org/D8PME