PHP: Array removed specifed keys from the array variable -
i have array, array key contains file name , array value array contain sfile size,date etc.
in these array list, want store xls , xlsx files alone. need remove files of other extensions.
is there predefined function in php?
note: have constant variable varaible contain var_file_ext= "xls, xlsx, csv"
[sample.xls] => array ( [size] => 3353 [uid] => 1012 [gid] => 1013 [permissions] => 33188 [atime] => 1338497357 [mtime] => 1338497357 [type] => 1 ) [sample.csv] => array ( [size] => 3353 [uid] => 1012 [gid] => 1013 [permissions] => 33188 [atime] => 1338497357 [mtime] => 1338497357 [type] => 1 ) [sample.txt] => array ( [size] => 3353 [uid] => 1012 [gid] => 1013 [permissions] => 33188 [atime] => 1338497357 [mtime] => 1338497357 [type] => 1 )
in example want remove sample.txt array keys , corresponding values.
$filtered = array_intersect_key( $array, array_filter(array_keys($array), function ($name) { return preg_match('/\.xlsx?$/', $name); }) );
Comments
Post a Comment