I have an array that looks like this:
$arr = [
0 => "A",
1 => "B",
2 => "C",
3 => "D",
4 => "E",
];
And I want to delete few of the items, I have array of their keys:
$delKeys = [0,2,3];
The following procedure shows what I want to achieve:
foreach ($delKeys as $dk) {
unset($arr[$dk]);
}
I'm left with:
array(
[1] => "B",
[4] => "E",
)
Is there a build in method that does the above 3-liner, like array_filter, but preserving the keys of the original array?
foreachworks perfectly fine and I've shown the expected output with preserved keys. I'm wondering if there is build-in function that does the same.array_filterdoes it but it resets the keys (it generates new array with the non-filtered items).