Home > Backend Development > PHP Tutorial > php的回调函数问题

php的回调函数问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:36:21
Original
1160 people have browsed it

function a($args){
echo $args;
}

function b($args){
return $args;
}
a(b(6666)); //输出6666

// ************************

function c($callback){
echo $callback(3);
}

function d($args){
return $args;
}

c('d'); //输出3

2个例子都能正常运行,也就是说回调函数的参数可以直接把函数拿来传递,为什么书上还要通过变量函数来传递呢,不是多次一举吗

回复内容:

function a($args){
echo $args;
}

function b($args){
return $args;
}
a(b(6666)); //输出6666

// ************************

function c($callback){
echo $callback(3);
}

function d($args){
return $args;
}

c('d'); //输出3

2个例子都能正常运行,也就是说回调函数的参数可以直接把函数拿来传递,为什么书上还要通过变量函数来传递呢,不是多次一举吗

例子里传递的是函数名,不是函数。
你的例子就是书上所说的变量函数的一个实例。

Related labels:
php
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template