Question: ```
$arr1 = array(
  'a' => 123,
  'b' => 123,
  'c' => 123,
  'd' => 123,
);

$arr2 = ('a', 'b', 'c', 'd', 'e');

```

How can I remove elements from $arr2 that don't exist as keys in $arr1 ?

for example `e` doesn't exist as key in $arr1 so it should be removed

Answer: 
```
$arr2 = array_intersect($arr2, array_keys($arr1))

```

it computes intersection of two sets - `$arr2` values and `$arr1` keys
Try this:

```
foreach ( $arr2 as $key => $value ) {
    if ( !array_key_exists( $value, $arr1 ) ) {
        unset( $arr2[$key] );
    }
}

```