Press "Enter" to skip to content

PHP_使用【array_filter】函数对键值对数组过滤_设定不过滤某些键

$params = array(
    'uploadtime'     => time(),
    'download_int'   => 0,
    'download_float' => 0.00,
    'download_test'  => 0,
    'download_null'  => null,
    'download_arr'   => [],
    'download_bool'     => false
);

$notFliterKey = [
    'download_test',
];

$newparams = array_filter($params, function($value, $key) use ($notFliterKey){
    if(in_array($key, $notFliterKey) ){
        return true;
    }
    return $value;
}, ARRAY_FILTER_USE_BOTH);
var_dump($newparams);
发表评论