To clarify Traunβs answer, you want your array to be indexed by store_id. In the end you want:
array ( [1] => 100.00 [2] => 10.00 )
If you cannot just build it from the very beginning, but you are forced to work with this original array structure (let's call it $stores ), do the following:
$totals = array(); foreach ($stores as $store) { if (!array_key_exists($store['store_id'], $totals)) { $totals[$store['store_id']] = $store['amount']; } else { $totals[$store['store_id']] += $store['amount']; } }
There are many ways to check this array. empty and isset enough.
source share