I need to combine two multidimensional arrays to one array as the example provided below.
Booth arrays have same keys each time (0,1,2, ...)
The first array
The url1 or url2 are the same each time
Array
(
[0] => Array
(
[Id] => 1
[Title] => Example
[Url1] => https://example1.com
[Url2] => https://example2.com
)
[1] => Array
(
[Id] => 2
[Title] => Example
[Url1] => https://example1.com
[Url2] => https://example2.com
)
)
Second array
The keys of each array change every time (AL_url, MK_url, EN_url, SR_url, ...)
Array
(
[0] => Array
(
[AL_url] => ?api=123?label=al
[MK_url] => ?api=456?label=mk
)
[1] => Array
(
[EN_url] => ?api=789?label=en
)
)
Final result
The final array should lookalike:
[Url1] + [AL_url] + [MK_url] = https://example1.com?api=123?label=al?api=456?label=mk
Array
(
[0] => Array
(
[complete_url_1] => https://example1.com?api=123?label=al?api=456?label=mk
[complete_url_2] => https://example2.com?api=123?label=al?api=456?label=mk
)
[1] => Array
(
[complete_url_1] => https://example1.com?api=789?label=en
[complete_url_2] => https://example2.com?api=789?label=en
)
)
The code
for ($y = 0; $y < count($second); $y++) {
foreach ($second[$y] as $key => $value) {
$new[$y]['complete_url_1'] = $first[$y]['Url1'] . $second[$y][$key];
}
}
The response add the value only from the last key from second array
Array
(
[0] => Array
(
[complete_url_1] => https://example2.com?api=456?label=mk
**this should be https://example1.com?api=123?label=al?api=456?label=mk**
)
[1] => Array
(
[complete_url_1] => https://example1.com?api=789?label=en
)
)