我有这个数组:
$lista_agregados = array('po' => '0', 'brita' => '0');
而这些数组:
$po = array(0 => array('qt' => 12, 'total' => 1234),
1 => array('qt' => 45, 'total' => 13224));
$brita = array(0 => array('qt' => 54, 'total' => 124),
1 => array('qt' => 18, 'total' => 224));
我想对$lista_agregados中的每个键使用循环而不是显式操作:
$somatorio_mensal['po'] = $po[0]['total'] + $po[1]['total'];
$somatorio_mensal['brita'] = $brita[0]['total'] + $brita[1]['total'];
这是我到目前为止:
foreach ($lista_agregados as $key => $value) {
$somatorio_mensal["'$key'"] = $key[0]['total'] + $key[1]['total'];
}
问题是$key [0]被解释为po [0]而不是$po [0].
有没有办法让这项工作?