$array1 = ["local_price" => "309"];
$array2 = ["perc" => ['0.084','0.084']];
$array3 = ["international_price" => "312"];
$array2 = array_unique($array2['perc']);
$array4 = array_merge($array1,$array3);
$array4['perc'] = $array2[0];
print_r($array4);
Output:
Array
(
[local_price] => 309
[international_price] => 312
[perc] => 0.084
)
May 24, 2022
6
Level 1
Merging a multi dimensional array
I'm trying to merge 2 multi dimensional arrays. The only issue I'm having is that in both arrays there is a key called "perc" and because of that when I merge them together "perc" becomes an array with both of the "perc" values.
"pricing" => array:11 [
"local_price" => "309"
"perc" => array:2 [
0 => "0.084"
1 => "0.084"
]
"international_price" => "312"
]
The "perc" will always be the same.
What I'm trying to do is merge the arrays together and I would like "perc" to only have the one value so the array would look like this
"pricing" => array:11 [
"local_price" => "309"
"perc" => "0.084"
"international_price" => "312"
]
This is the code I've got
$localPrice = productService()->getLocalPrice($product->id);
$internationalPrice = productService()->getInternationalPrice($product->id);
$price = array_merge_recursive($localPrice, $internationalPrice);
Please or to participate in this conversation.