1$my_array = ['foo' => 1, 'hello' => 'world'];
2$allowed = ['foo', 'bar'];
3$filtered = array_filter(
4 $my_array,
5 function ($key) use ($allowed) {
6 return in_array($key, $allowed);
7 },
8 ARRAY_FILTER_USE_KEY
9);
1?php
2$data= [
3 0 => [1, 'test1'],
4 1 => [2, 'test2'],
5 2 => [3, 'test3'],
6];
7
8$ids = array_map(function($item) {
9 return $item[0];
10}, $data);
11
12var_dump($ids);