Home >Backend Development >PHP Tutorial >How to use the method in array_map?
array_map(function($v)use($status){
<code> return $this->_formatProject($v,$status);</code>
},$projects)
array_map(function($v)use($status){
<code> return $this->_formatProject($v,$status);</code>
},$projects)
As you can see
<code>array_map(function($v) use($status){ return $this->_formatProject($v,$status); },$projects);</code>
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>