php - Group arrays by key value -
i have problem approaching issue have, need group arrays
key
value
i have 3 foreach functions
foreach ($report_phonecall $key=>$value) { $phonecalls[$value['datum']] = $value['broj']; }; foreach ($report_meeting $key=>$value) { $meetings[$value['datum']] = $value['broj']; } foreach ($report_notes $key=>$value) { $notes[$value['datum']] = $value['broj']; }
that give me array
$phonecall = array ( [2016-07-13] => 2 [2016-07-14] => 1 [2016-07-19] =>1 ) $meetings = array ( [2016-07-13] => 1 [2016-07-14] => 1 ) $notes = array ( [2016-07-19] => 1 )
i need merge them 1 array
foreach date this
array(2016-07-13 => array([phonecalls]=>2, [meetings]=>1, [notes]=>0)) 2016-07-14 => array([phonecalls]=>1, [meetings]=> 1, [notes]=>0).... etc
i want group/sort them key value.
going
$group_reports[$value[key]] = $value['broj'][$phonecalls][$meetings][$notes]
im not sure how define it
please use below code merge array
$finalarr = array(); foreach($phonecall $key=>$val){ $finalarr[$key]['phonecalls'] = $val; $finalarr[$key]['meetings'] = 0; $finalarr[$key]['notes'] = 0; } foreach($meetings $key=>$val){ if(array_key_exists($key, $finalarr)){ $finalarr[$key]['meetings'] = $val; } else { $finalarr[$key]['phonecalls'] = 0; $finalarr[$key]['meetings'] = $val; $finalarr[$key]['notes'] = 0; } } foreach($notes $key=>$val){ if(array_key_exists($key, $finalarr)){ $finalarr[$key]['notes'] = $val; } else { $finalarr[$key]['phonecalls'] = 0; $finalarr[$key]['meetings'] = 0; $finalarr[$key]['notes'] = $val; } }
Comments
Post a Comment