I have two arrays.
The first $letters is simple:
[5, 89, 1, 212]
The second $some_data:
[
89 => 'A',
41 => 'B',
1 => 'C',
5 => 'D',
200 => 'E',
212 => 'F'
]
How to merge those arrays to get:
[
89 => 'A',
1 => 'C',
5 => 'D',
212 => 'F'
]
I have already tried
foreach($some_data as $id => $title) {
if (array_key_exists($id, $letters)) {
$some_arr[$id] = $title;
}
}
But for some reason it's not working properly and $some_arr is duplicated. This function, that fills up $some_arr is called inside a loop and accepts one parameter. Using this parameter, I fill up array $letters. Each time (in general 6 times) array $letter is different
$some_arr wasn't duplicated, when it used to fill up this way:
foreach($cont_cntrs as $cntr_id) {
$cntrs_byletter[$cntr_id] = $countries[$cntr_id];
}
But it wasn't sorted by $countries id's order