Have such array (placed code here http://codepad.viper-7.com/mTqf6W)
Array
(
[17,bank stmt,1,23,3,2014] => Array
(
[0] => Array
(
[RecordDay] => 17
[Amount] => 1.5
)
)
[17,invoice,2,17,3,2014] => Array
(
[0] => Array
(
[RecordDay] => 17
[Amount] => 0.21
)
[1] => Array
(
[RecordDay] => 17
[Amount] => 1
)
)
)
Want to get totals of [Amount]
for each subarray. For the first subarray there is only one key, so Total equals to [Amount]
. But for the second subarray there are 2 keys (may be more than 2 keys), so in some way need to sum all [Amount]
For [17,bank stmt,1,23,3,2014]
would be 1.5, [17,invoice,2,17,3,2014]
would be 1.21
Following some examples PHP Array_Sum on multi dimensional array trying to create code. Created
$values = array('Amount' => 0);
$counter = 0;
foreach ($temp_array as $key => $item) {
$values['Amount'] += $item[$counter]['Amount'];
$counter++;
}
Get error 'Notice: Undefined offset: 2'