PHP闭包特性应用:代替循环,提高代码性能。_PHP教程

WBOY
Release: 2016-07-20 11:14:14
Original
1372 people have browsed it

起因是看到了一个简单php上传脚本:http://www.nowamagic.net/librarys/veda/detail/1384

我重构了一下,主要是用匿名函数代替了foreach循环,利用了闭包的新特性,从而也提高了性能。需要注意的是闭包并不就完全等于匿名函数,闭包是通过匿名函数实现的,跟use关键字的使用有关。

记录下就当抛砖引玉了,毕竟随着php众多新特性的加入,我们程序员也要与时俱进不断优化代码,重构自身。
以下是重构后的php部分:

 = ['img' (
     = ((['tmp_name'],  () (,
         = ['name'][(, ['tmp_name'
         ="\\"
         = (, 
        ( "<span $filename</span> "
Copy after login

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440316.htmlTechArticle起因是看到了一个简单php上传脚本:http://www.nowamagic.net/librarys/veda/detail/1384 我重构了一下,主要是用匿名函数代替了foreach循环,利用了闭包...
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!