Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php array filter specific keys

$arr = [
    'foo' => 'bar',
    1 => 'baz',
    'qux' => 22,
    3 => 123,
    'quux' => 'quuz',
];

$filteredArr = array_filter(
    $arr,
    fn ($key) => is_numeric($key),
    ARRAY_FILTER_USE_KEY
);

echo print_r($filteredArr, true); // [1 => 'baz', 3 => 123]
 
PREVIOUS NEXT
Tagged: #php #array #filter #specific #keys
ADD COMMENT
Topic
Name
1+4 =