array_filter()的回调函数,PHP的奇技淫巧。

WBOY
Release: 2016-06-23 13:58:14
Original
1379 people have browsed it

昨天看项目代码,看到一行代码大概是这么写的
array_filter($array, array($this, 'functionName');
以前没见过这种写法,functionName是控制器的一个方法名。好奇这种回调方式php是如何运作的?还有就是从哪里能学到这种php的奇技淫巧,我看php手册上都没有这种写法的介绍啊。


回复讨论(解决方案)

array array_filter ( array input [, callback callback] )

如果 callback 是对象的方法应写作 array(对象名, 方法名)
不过本人阅读的不多,并没有见到该表述的权威文档,也不记得是如何知道这个表述方式的

手册上有写:
一个对象的方法以数组的形式来传递,数组的下标 0 指明对象名,下标 1 指明方法名。
对于没有实例化为对象的静态类,要传递其方法,将数组 0 下标指明的对象名换成该类的名称即可。

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!