Home  >  Article  >  Backend Development  >  Sharing examples of variable functions and anonymous functions in PHP

Sharing examples of variable functions and anonymous functions in PHP

小云云
小云云Original
2018-03-10 09:37:451458browse

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 = &#39;fun&#39;;//将方法名称保存到变量中。$str(&#39;i am  fun&#39;);//用变量名称去匹配函数,
并调用。echo &#39;<br>&#39;;
//匿名函数 PHP从 5.3 开始支持匿名函数。$fn = function($args){
    echo $args;
};//注意匿名函数必须以;结尾。var_dump($fn);echo &#39;<br>&#39;;$fn(&#39;i am 奥巴马~!&#39;);?>

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn