How to save specific items from array using array keys.
INPUT:
$arr = [
0 => 'item0',
2 => 'item2',
4 => 'item4',
43 => 'item43'
];
Now I only want to save keys 2 and 43.
Expected Output:
$arr = [
2 => 'item2',
43 => 'item43'
];
Current Code:
foreach ($arr as $key => $value) {
if(!($key == 2 || $key == 43)) {
unset($arr[$key]);
}
}
It works for now, but what if i have more array keys to save.