I have an array as following. I order that array by the value of the key "attack". Everything is ok until then, but I want to get for example only 9 of that total attack values are summed up: I want to sum up 3 of key1 (3 * 45), 4 of key3 (4 * 35) and 2 of key2 (2* 25) are automatically summed up. I would be greatly appreciated if somebody help.
Here is the array:
$data = array(
'1' => array('id' => '1', 'attack' => '45', 'defence' => '15', 'total' => '3'),
'2' => array('id' => '2', 'attack' => '25', 'defence' => '15', 'total' => '6'),
'3' => array('id' => '3', 'attack' => '35', 'defence' => '15', 'total' => '4'),
'4' => array('id' => '4', 'attack' => '20', 'defence' => '10', 'total' => '4')
);