Ch037 Ch037 - 2 months ago 7
PHP Question

Need to convert array using 2 array

I have 2 arrays like below

Array1 = Array(
[8756] => 1A10
[8758] => 1B20
[8770] => 1B25
)

Array2 = Array(
[8756] => 413072-FT6
[8758] => 413072-HT4
[8770] => 413072-WT4
)


Above both array have the same key and diff value I need the new array which have the structure like below

Array
(
[8756] => Array
(
[loc] => 1A10
[sku] => 413072-FT6
)

[8758] => Array
(
[loc] => 1B20
[sku] => 413072-HT4
)

[8770] => Array
(
[loc] => 1B25
[sku] => 413072-WT4
)

)

Answer

You just need to loop and then grab the right parts

$locs = //your array1;
$skus = //your array2;
$merged = array(); //what to add it to
foreach($locs as $key => $value){ //need key to place in merged and grab from skus
    $merged[$key]['loc'] = $value;
    $merged[$key]['sku'] = $skus[$key];
}
Comments