<?php
"pei_seq" => "0",
"prg_cod_barra" => "7899619704729" ,
"pei_prg_cod" => "483",
"pei_valor" => "42.00" ,
"pei_quantidade" => "1"
),
"pei_seq" => "0",
"prg_cod_barra" => "7899619704729" ,
"pei_prg_cod" => "483",
"pei_valor" => "42.00" ,
"pei_quantidade" => "1"
),
"pei_seq" => "0",
"prg_cod_barra" => "7899619704729" ,
"pei_prg_cod" => "483",
"pei_valor" => "42.00" ,
"pei_quantidade" => "1"
),
"pei_seq" => "0",
"prg_cod_barra" => "7899619704729" ,
"pei_prg_cod" => "483",
"pei_valor" => "42.00" ,
"pei_quantidade" => "1"
)
);
$nova = [];
foreach ($original as $arr) { // itera a array original
$prg_cod_barra = $arr['prg_cod_barra'];
$existe = false;
foreach ($nova as &$subArr) { // iterar a array nova à procura de igual
// se houver igualdade
if ($prg_cod_barra == $subArr['prg_cod_barra']){
$valorAntigo = intval($subArr['pei_quantidade'], 10); $novoValor = intval($arr['pei_quantidade'], 10); $existe = strval($valorAntigo + $novoValor); // inserir o novo numero $subArr['pei_quantidade'] = $existe;
}
}
if (!$existe) $nova[] = $arr;
}
PD9waHAKCiRvcmlnaW5hbCA9IGFycmF5KAoJYXJyYXkoCgkJInBlaV9zZXEiID0+ICAiMCIsCiAgICAgIAkicHJnX2NvZF9iYXJyYSIgPT4gICI3ODk5NjE5NzA0NzI5IiAsCiAgICAgIAkicGVpX3ByZ19jb2QiID0+ICAiNDgzIiwKICAgICAgCSJwZWlfdmFsb3IiID0+ICAiNDIuMDAiICwKICAgICAgCSJwZWlfcXVhbnRpZGFkZSIgPT4gICIxIgogICAgKSwKCWFycmF5KAoJCSJwZWlfc2VxIiA9PiAgIjAiLAogICAgICAJInByZ19jb2RfYmFycmEiID0+ICAiNzg5OTYxOTcwNDcyOSIgLAogICAgICAJInBlaV9wcmdfY29kIiA9PiAgIjQ4MyIsCiAgICAgIAkicGVpX3ZhbG9yIiA9PiAgIjQyLjAwIiAsCiAgICAgIAkicGVpX3F1YW50aWRh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