I've one array titled $post_data
. I want to pass this array to some function as an argument. Along with this array I've to pass another argument the callable 'function name' as second argument in a function call.
I'm not understanding how to achieve this.
Following is the function body which needs to be called:
//Following is the function to be called
function walk_recursive_remove(array $array, callable $callback) {
foreach ($array as $k => $v) {
if (is_array($v)) {
$array[$k] = walk_recursive_remove($v, $callback);
} else {
if ($callback($v, $k)) {
unset($array[$k]);
}
}
}
return $array;
}
//Following is the callback function to be called
function unset_null_children($value, $key){
return $value == NULL ? true : false;
}
The function call that I tried is as follows:
//Call to the function walk_recursive_remove
$result = walk_recursive_remove($post_data, unset_null_children);
Can someone please help me in correcting the mistake I'm making in calling the function?
Thanks in advance.