array filter use key

Solutions on MaxInterview for array filter use key by the best coders in the world

showing results for - "array filter use key"
Maximiliano
07 Aug 2016
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);
Tommaso
22 Jun 2020
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);
similar questions
queries leading to this page
array filter use key