Php 如何访问声明为变量的函数中的变量?
可能重复:Php 如何访问声明为变量的函数中的变量?,php,scope,Php,Scope,可能重复: 给定此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?目前,$ty
给定此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
为数组过滤器返回NULL
,而不管传递给按类型获取交易的值是什么()
不确定,但:
function get_deals_by_type($records, $type) {
$available = function($record) use ($type) {
if($record->mobile_type == $type) return $record;
};
return array_filter($records, $available);
}
请参见(购物车示例)是!正是我想要的。谢谢