You can create a closure on PHP ≥5.3.
array_filter($files, function($array) use ($key) {
return is_inarr_key($array, $key);
} );
If you are stuck with PHP <5.3, …
You can make $key
a global variable.
function is_inarr_with_global_key($array) {
global $key;
....
}
You can create a class
class KeyFilter {
function KeyFilter($key) { $this->key = $key; }
function is_inarr_key($array) { ... }
}
...
array_filter($files, array(new KeyFilter('name'), 'is_inarr_key'));
You can create 3 different functions
array_filter($files, 'is_inarr_name');
array_filter($files, 'is_inarr_path');
array_filter($files, 'is_inarr_number');
You can write your own array_filter
function my_array_filter($files, $key) {
...
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…