Here is my First Array
$array1 = [
'A' => 'Apple',
'B' => 'Ball',
'C' => 'Cat',
'E' => 'Eagle',
'F' => 'Fan'
];
Second Array
$array2 = [
'A' => 'apple is a fruit',
'B' => 'ball is used to play',
'C' => 'cat is an animal',
'D' => '',
'E' => 'eagle is a bird',
'F' => ''
];
Current Output:
Array
(
[Apple] => apple is a fruit
[Ball] => ball is used to play
[Cat] => cat is an animal
[Eagle] => eagle is a bird
[Fan] =>
)
Expected Output:
Array
(
[Apple] => apple is a fruit
[Ball] => ball is used to play
[Cat] => cat is an animal
[Eagle] => eagle is a bird
)
I have tried like this
$arr4 = [];
if ($arr3 = array_intersect_key($array1, $array2)) {
foreach ($arr3 as $k => $v) {
$arr4[$v] = $array2[$k];
}
}
print_r($arr4);
Please help, Thanks in advance! If you see the current output, I am getting the result of Fan which has no value. I need to get the results which are having values like the expected output