Based on @Hristo response, I modified the code and it worked the following way. By this way, I get the expected output.
Below is not the exact code that I used. I have modified to be in alignment with my example posted in the question.
Will this work well in a huge array?
$finalArray = array();
foreach ($apple as $key => $value) {
$finalArray[$value['date']]['apple'] = $value['apple'];
}
foreach ($banana as $key => $value) {
$finalArray[$value['date']]['banana'] = $value['banana'];
}
var_dump($finalArray);
This gives an output of
array
(
[1] => array
(
[apple] => 5
[banana] => 3
)
)