Home > Backend Development > PHP Tutorial > How to use the method in array_map?

How to use the method in array_map?

WBOY
Release: 2016-08-20 09:04:05
Original
2407 people have browsed it

array_map(function($v)use($status){

<code>   return $this->_formatProject($v,$status);</code>
Copy after login
Copy after login

},$projects)

Reply content:

array_map(function($v)use($status){

<code>   return $this->_formatProject($v,$status);</code>
Copy after login
Copy after login

},$projects)

As you can see

<code>array_map(function($v) use($status){
    return $this->_formatProject($v,$status);
},$projects);</code>
Copy after login

There is closure here. The method of passing parameters to closures in PHP is currently recommended user, and you can use global

in older versions.

When the closure wants to use external variables, use use.

<code class="php"><?php 
$i = 1;
$callback = function($params) {
    echo $i;    //不能这样使用$i
};

$callback = function($params) use ($i) {
    echo $i;    //正确的用法
};</code>
Copy after login
Related labels:
php
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