Somar valores de um Array com Condição
Olá Pessoal, estou com um problema simples, porém não estou conseguindo resolver, tenho a seguinte array:
/* $array_frete_calc =
0:{partner_id: 2, weight: 5.6, length: 140, height: 140, width: 140}
1:{partner_id: 2, weight: 2.4, length: 75, height: 75, width: 75}
2:{partner_id: 2, weight: 2.4, length: 75, height: 75, width: 75}
3:{partner_id: 1, weight: 1.0, length: 75, height: 75, width: 75}
*/
Em teoria, fiz o foreach abaixo na intenção de somente agrupar os partner_id que forem iguais, e somar os campos weight, length, height e width.
Como verifico se existe o campo partner_id = > $value['partner_id'] dentro do array $array_frete_calc ???
Podem me ajudar? O ele está funcionando certinho.
$array_frete_calc = array();
foreach($products_group_qtde as $key => $value) {
// Como verifico se existe o campo partner_id = > $value['partner_id'] dentro do array $array_frete_calc
if(){
// return false
} else {
array_push($array_frete_calc,
array(
"partner_id" => $value['partner_id'],
'weight'=> $value['weight'],
'length'=> $value['length'],
'height'=> $value['height'],
'width'=> $value['width']
)
);
}
}
return $array_frete_calc;Discussão (1)
Carregando comentários...