Here I have two multidimensional arrays. I have to combine them to make one multidimensional array. I tried but it is not happening. I don't know what I am doing wrong. I want to make productId as index, then values.
With this code:
$array1 = Array (
"3" => Array ( "productId" => 3, "brandName" => "Honor" ),
"4" => Array ( "productId" => 4, "brandName" => "Puma" )
);
$array2 = Array ( "5" => Array ( "productId" => 5, "brandName" => "Dell" ) )
$result = array_merge($array1,$array2);
print_r($result );
I get:
Array (
"0" => Array ( "productId" => 3, "brandName" => "Honor" ),
"1" => Array ( "productId" => 4, "brandName" => "Puma" ),
"2" => Array ( "productId" => 5, "brandName" => "Puma" )
)
The above result is not my expected answer because index is automatically assigning. In my case, the index is productId.
Expected Result:
Array (
"3" => Array ( "productId" => 3, "brandName" => "Honor" ),
"4" => Array ( "productId" => 4, "brandName" => "Puma" ),
"5" => Array ( "productId" => 5, "brandName" => "Dell" )
)