Assignment to variables

suggest change

Anonymous functions can be assigned to variables for use as parameters where a callback is expected:

$uppercase = function($data) {
    return strtoupper($data);
};

$mixedCase = ["Hello", "World"];
$uppercased = array_map($uppercase, $mixedCase);
print_r($uppercased);

These variables can also be used as standalone function calls:

echo $uppercase("Hello world!"); // HELLO WORLD!

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents