The PHP function that I'm looking for is similar to array_intersect_key()
.
If I have an associative array called $populations[]
, and a numerical array called $countries[]
, which function will return a modified version of $populations[]
with only keys present as values in $countries
?
Here's a pair of arrays that I may want such a function for:
$populations = [
'Sweden' => 6476727,
'Denmark' => 3722898,
'Finland' => 3417691,
'Norway' => 3511912,
'Iceland' => 247524
];
$countries = [
'Sweden',
'Denmark',
'Norway'
];
Which function will take those two arrays as input, and output the following array?
['Sweden']=> 6476727
['Denmark']=> 3722898
['Norway']=> 3511912