-1
$original array [['type_of_activity'=>'م.ص','total'=>'0' ],['type_of_activity'=>'م.و','total'=>'0'],['type_of_activity'=>'م.ن','total'=>'0'],['type_of_activity'=>'م.خ','total'=>'0'],['type_of_activity'=>'م.ت','total'=>'0'],['type_of_activity'=>'و.ش','total'=>'0'],['type_of_activity'=>'ق.ع','total'=>'0'],
    ['type_of_activity'=>'م.و','total'=>'0'],['type_of_activity'=>'م.غ','total'=>'0'],['type_of_activity'=>'س.ن','total'=>'0'],['type_of_activity'=>'ح.ف','total'=>'0']]

that there areport based on this value

the return array from DB my be ['type_of_activity'=>'م.و','total'=>'5'],['type_of_activity'=>'م.غ','total'=>'10'],['type_of_activity'=>'س.ن','total'=>'15'] is there a way to map this array to the original array where the match keys without losing any key or value

the result will be just 11 arrays within the original

[['type_of_activity'=>'م.ص','total'=>'0' ], [['type_of_activity'=>'م.ع','total'=>'0' ], ['type_of_activity'=>'م.و','total'=>'5'],['type_of_activity'=>'م.ن','total'=>'0'],['type_of_activity'=>'م.خ','total'=>'0'],['type_of_activity'=>'م.ت','total'=>'0'],['type_of_activity'=>'و.ش','total'=>'0'],['type_of_activity'=>'ق.ع','total'=>'0'], ['type_of_activity'=>'م.غ','total'=>'10'],['type_of_activity'=>'س.ن','total'=>'15'],['type_of_activity'=>'ح.ف','total'=>'0']],

1 Answers1

1

You can use array_merge,

$c = array_merge($a,$b);
print_r($c);

Demo

O/p

Array
(
    [mw] => 0
    [mg] => 5
    [ma] => 0
    [sn] => 0
    [fa] => 0
    [mn] => 10
)
Rahul
  • 18,271
  • 7
  • 41
  • 60