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

Sharing examples of variable functions and anonymous functions in PHP

小云云
Release: 2023-03-21 07:08:02
Original
1504 people have browsed it

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;);?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template