Problem: see the inline comments in the following code:
[code=php]<?php
$array1 = array(
‘key1’ => array(
‘name’ => ‘Product1.1′
,’price’ => 220
,’qty_in_x’ => 100
)
,’key2′ => array(
‘name’ => ‘Product1.2′
,’price’ => 120
,’qty_in_x’ => 150
)
/* and so on… */
);
$array2 = array(
‘key11’ => array(
‘name’ => ‘Product2.1′
,’price’ => 50
,’qty_in_y’ => 150
)
,’key2′ => array(
‘name’ => ‘Product2.2′
,’price’ => 80
,’qty_in_y’ => 180
)
/* and so on… */
);
//what i want to do is intersect the two arrays by keys and want to get the results as:
$final_array = array(
‘key2’ => array(
‘name’ => ‘Product1.2′
,’price’ => 120
,’qty_in_x’ => 150
,’qty_in_y’ => 180 //Note: this should be merged from $array2
)
);
//I tried with:
$final_array = array_intersect_key($array1, $array2);
print_r($final_array);
/*Which Results:
Array
(
[key2] => Array
(
[name] => Product1.2
[price] => 120
[qty_in_x] => 150
)
)
which just gave the fields from $array1 excluding ‘qty_in_y’
*/
?>
Is there any way to accomplish as mentioned above?
Thanks