Callbacks¶
Callbacks are functions or methods which are used as parameters for other functions. Such functions are used to customize the calling function. For example, array_map(), which applies a callback to every element of an array, or usort(), which sorts an array using a function.
Callback is akin to a functioncall : it is actually hidden inside the caller function.
Callback may be build with on closures, arrow-functions, native PHP functions, methods and static methods. They also use string (such as ‘strtolower’) and array (such as [X::class, ‘methodName’], or [$object, ‘methodName’] ) syntax. In fact, anything that is_callable() may be used.
<?php
$array = ['Damien', 'Dan', 'Daniel', 'Davey', 'David', 'Dennis', 'Derick', 'Dmitry', 'Dustin',];
$array = array_map('strtolower', $array);
//['damien', 'dan', 'daniel', 'davey', 'david', 'dennis', 'derick', 'dmitry', 'dustin',];
?>
See also The Wonderful World of Callbacks, Using callbacks to prevent code duplication
Related : Callables, Closure, Arrow Functions