A lambda function is an anonymous PHP function that can be stored in a variable and passed as an argument to other functions or methods. A closure is a lambda function that is aware of its surrounding context. For example –
1 2 3 4 5 6 7 8 |
<?php $input = array(1, 2, 3, 4, 5); $output = array_filter($input, function ($v) { return $v > 2; }); ?> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.