php compare 2 associative arrays and combine on the same Key only -


i have special condition need combine 2 associative array on same keys only

$array_1['key1']=""; $array_1['key2']=""; $array_1['key3']=""; $array_1['key4']=""; $array_1['key5']=""; $array_1['key6']=""; $array_1['key7']="";  $array_2['key1']="value1"; $array_2['key3']="value2"; $array_2['key4']="value3"; $array_2['key8']="value4";  $results=array_merge($array_1,$array_2);  foreach ($results $key=>$value){  echo ''.$key.'-<input type="text" value="'.$value.'"><br>'; } 

if use array_merge, keys combined together, right side of screenshot; that's not want. want left side of screenshot

to put simpler, want display $array_1 keys , join $array_2 $array_1 same keys only.

enter image description here can help?

there many ways reach goal. 1 of them use array_intersect_key() keep values of $array_2 keys has in common $array_1 , merge intersection $array_1.

something like:

$results = array_merge($array_1, array_intersect_key($array_2, $array_1)); 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -