What is the default value for callback argument of array_filter function?
Let imagine we have array:
$input = [
"Required field" => true
"Please, enter a number" => false
];
Normally, I use array_filter without explicitly setting callback parameter, as array_filter( $input) and this function will return the following array:
$input = [
"Required field" => true
];
But now I need to exactly set callback argument. So when I'm sending null as callback this functions return null and "non empty" value ("Required field" => true) is ignored, what would I not like.
Of course, I can call the function with own callback function like:
array_filter( $input, fn($item) => !empty($item) )
But I was hoping for more elegant way
array_filterwithout a callback is not sufficient for you?If no callback is supplied, all empty entries of array will be removed. See empty() for how PHP defines empty in this case.callbackargument, but in more elegant way rather than setting own callback function.array_filter_recursivefunction. Like in this example: stackoverflow.com/a/6795671/7265862. As you see, in the second function, there is$callbackargument, which later will be passed toarray_filterfunction. I don't want to make if else statement to check for null$callbackargument. That's why I was asking community for elegant solution