【发布时间】:2012-01-22 10:11:13
【问题描述】:
可能重复:
Is it possible to access outer local variable in PHP?
PHP closure scope problem
给定这个 PHP 函数:
function get_deals_by_type($records, $type) {
$available = function($record) {
if($record->mobile_type == $type) return $record;
};
return array_filter($records, $available);
}
...如何访问在$available 中声明的函数内部传入的$type?就目前而言,$type 为array_filter 返回NULL,无论传递给get_deals_by_type() 的值是什么。
【问题讨论】: