dongxiaoyan4388
2013-12-27 16:49
浏览 12
已采纳

在PHP中使用匿名函数

This question may be silly. But an anonymous function does not really seem that anonymous to me. Maybe I am understanding it wrong, but an anonymous function must be stored in some variable, so it can later be referenced by this variable. If this is the case, what makes the below function so anonymous or so different than a regular function (other than the ability to store the function itself in a variable)? Or to word it differently, how is an anonymous function MORE useful than a regular function?

<?php
$greet = function($name)
{
    printf("Hello %s
", $name);
};

function greet($name)
{
     printf("Hello %s
", $name);
}

$greet('World');
$greet('PHP');

greet('World');
greet('PHP');
?>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题