i have a array:
Array
(
[0] => Array
(
[cam_id] => 136
[partner_id] => 350
[marketing] => [{"quartername":"q1","tactic":"Linkedin(Connections & Pages)","1":"9000","2":"4000","3":"3000","4":"2000","5":"1400","6":"1000","7":"700","8":"600","9":"500","10":"65"},{"quartername":"q1","tactic":"Single Email Campaign","1":"350","2":"200","3":"156","4":"142","5":"122","6":"112","7":"80","8":"65","9":"35","10":"15"},{"quartername":"q4","tactic":"Single Email Campaign","1":"350","2":"200","3":"156","4":"142","5":"122","6":"112","7":"80","8":"65","9":"35","10":"15"}]
)
)
after decode the jason of "marketing" key value i got this array.
Array
(
[0] => Array
(
[quartername] => q1
[tactic] => Linkedin(Connections & Pages)
[1] => 9000
[2] => 4000
[3] => 3000
[4] => 2000
[5] => 1400
[6] => 1000
[7] => 700
[8] => 600
[9] => 500
[10] => 65
)
[1] => Array
(
[quartername] => q1
[tactic] => Single Email Campaign
[1] => 350
[2] => 200
[3] => 156
[4] => 142
[5] => 122
[6] => 112
[7] => 80
[8] => 65
[9] => 35
[10] => 15
)
[2] => Array
(
[quartername] => q4
[tactic] => Single Email Campaign
[1] => 350
[2] => 200
[3] => 156
[4] => 142
[5] => 122
[6] => 112
[7] => 80
[8] => 65
[9] => 35
[10] => 15
)
)
i want to check the "quartername" key if the key match in the array then there respective added.
i want the result array just like after adding the same "quartername" key:
Array
(
[0] => Array
(
[quartername] => q1
[tactic] =>
[1] => 9350
[2] => 4200
[3] => 3156
[4] => 2142
[5] => 1522
[6] => 1112
[7] => 780
[8] => 665
[9] => 535
[10] => 80
)
[1] => Array
(
[quartername] => q4
[tactic] => Single Email Campaign
[1] => 350
[2] => 200
[3] => 156
[4] => 142
[5] => 122
[6] => 112
[7] => 80
[8] => 65
[9] => 35
[10] => 15
)
)
here is the code which i tried .it will add all the values of "quartername" key.
foreach($actual_leads as $key => $val){
$actual_leads[$key]['marketing'] = json_decode($actual_leads[$key]['marketing'],true);
echo "<pre>"; print_r($actual_leads[$key]['marketing']);echo "</pre>";
}
$actual_leads_tot = array();
foreach($actual_leads as $key => $val){
foreach($val as $key2 => $val2){
foreach($val2 as $key3=> $val3){
foreach($val3 as $key4=>$val4){
if($key4 != 'quartername' && $key4 != 'tactic'){
$actual_leads_tot[$key][$key4] += $val4;
$actual_leads[$key]['marketing'] = $actual_leads_tot;
}
}
}
}
}