This article mainly shares with you examples of variable functions and anonymous functions in PHP, hoping to help everyone.
<?php//可变函数function fun($args){ echo $args; }$str = 'fun';//将方法名称保存到变量中。$str('i am fun');//用变量名称去匹配函数, 并调用。echo '<br>'; //匿名函数 PHP从 5.3 开始支持匿名函数。$fn = function($args){ echo $args; };//注意匿名函数必须以;结尾。var_dump($fn);echo '<br>';$fn('i am 奥巴马~!');?>
Related recommendations:
php variable function analysis
php variable function example detailed explanation
Detailed explanation of how to use variable functions in php
The above is the detailed content of Sharing examples of variable functions and anonymous functions in PHP. For more information, please follow other related articles on the PHP Chinese website!