Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

only fetch specific array keys php

$array = [
    'a' => 4,
    's' => 5,
    'd' => 6,
];
$onlyKeys = ['s','d'];

$filteredArray = array_filter($array, function($v) use ($onlyKeys) {
    return in_array($v, $onlyKeys);
}, ARRAY_FILTER_USE_KEY);

prinr_r($filteredArray); //  ['s' => 5, 'd' => 6]
 
PREVIOUS NEXT
Tagged: #fetch #specific #array #keys #php
ADD COMMENT
Topic
Name
3+2 =