根据键值取消设置数组元素

I have an array like this:

$occurrences = 
Array
(
[103] => 3
[1002] => 1
[100] => 2
[2001] => 1
)

And I want to produce a new array with php that lacks all lines with keys > 1000. Therefore, this:

Array
(
[103] => 3
[100] => 2
)

I believe that I will have to use unset() to do so but I am unsure how to loop through each key and check if it should be unset. I initially tried array_flip but quickly realized that it wouldn't work as I would not have unique keys.

Thanks!

You just need a conditional on the key to check if it's greater than 1000 and then unset the value at that key:

foreach($occurences as $key => $value) {
  if($key > 1000) unset($occurrences[$key]);
}