I am currently working through the CakePHP Cookbook. Doing so, i stumbled across Collection and its methods. Almost every method is given a callable calback function as a parameter. In the Cookbook there are some examples.
This example from the Cookbook makes totally sense for me as there is a callback function that has two parameters which both are used in the function itself:
$collection = $collection->each(function ($value, $key){
echo "Elemement $key: $value;
});
Meanwhile I do not understand this example (chapter “Collections, Quick Example”)
$overOne = $collection->filter(function ($value, $key, $iterator){
return $value > 1;
});
Why does this function require three parameters of which two are not used? Where is the number of parameters for callback function defined?
There are more examples of callback functions that do have parameters that are not used so I guess this is no mistake but I cannot find any description about that topic in the Cookbook…