Why and how do you use anonymous functions in PHP?

前端 未结 6 1647
天命终不由人
天命终不由人 2020-11-27 16:14

Anonymous functions are available from PHP 5.3.
Should I use them or avoid them? If so, how?

Edited; just found some nice trick with php anonymo

6条回答
  •  独厮守ぢ
    2020-11-27 16:49

    A typical use of anonymous functions is callback functions. For example, you could use them for callback from sort algorithms such as in function uksort ( http://lv.php.net/uksort ) or replacing algorithms such as preg_replace_callback ( http://lv.php.net/manual/en/function.preg-replace-callback.php ). Have not tried it myself in PHP, so this is just a guess.

提交回复
热议问题