I have 2 multidimensional arrays. I need to merge the content from the second array into first array.
First array consists of dates and/or some urls.
array:2 [
0 => array:3 [
0 => array:2 [
"startDate" => "2022-01-01"
"endDate" => "2022-01-31"
]
1 => array:2 [
"startDate" => "2022-02-01"
"endDate" => "2022-02-28"
]
2 => array:4 [
"startDate" => ""
"endDate" => ""
"bannerUrl" => "https://commons.wikimedia.org/wiki/File:Red_rose_flower_detailed_imge.jpg"
"imageTarget" => "image Target"
]
]
1 => array:1 [
0 => array:2 [
"startDate" => "2022-01-01"
"endDate" => "2022-01-15"
]
]
]
Second array consists of image objects.
array:2 [
0 => array:2 [
0 => array:1 [
"image" => {"image A object...."}
]
1 => array:1 [
"image" => {"image B object...."}
]
]
1 => array:1 [
0 => array:1 [
"image" => {"image C object...."}
]
]
]
I need output like this where image from second array is passed to first array.
array:2 [
0 => array:3 [
0 => array:2 [
"startDate" => "2022-01-01"
"endDate" => "2022-01-31"
"image" => {"image object...."}
]
1 => array:2 [
"startDate" => "2022-02-01"
"endDate" => "2022-02-28"
"image" => {"image object...."}
]
2 => array:4 [
"startDate" => ""
"endDate" => ""
"bannerUrl" => "https://commons.wikimedia.org/wiki/File:Red_rose_flower_detailed_imge.jpg"
"imageTarget" => "image Target"
]
]
1 => array:1 [
0 => array:2 [
"startDate" => "2022-01-01"
"endDate" => "2022-01-15"
"image" => {"image object...."}
]
]
]
This is code, I have tried.
foreach ($items as $key => $item) {
for ($i = 0; $i < count($item); ++$i) {
$executionArray[$key][$i] = $item[$i];
if (isset($files[$key])) {
if (isset($executionArray[$key][$i])) {
$executionArray[$key][$i]['image'] = $files[$key][$i]['image'];
}
}
}
}
But I am only getting Undefined array key 2
.