array_map并将 2 个参数传递给映射函数 - array_map():参数 #3 应该是一个数组
我有一个抽象类,看起来像这样:
abstract class Transformer {
/**
* Transform a collection of items
*
* @param array $items
* @param bool $format
* @return array
*/
public function transformCollection(array $items, $format)
{
return array_map([$this, 'transform'], $items, $format);
}
/**
* Transform a item
*
* @param array $item
* @param bool $format
* @return mixed
*/
public abstract function transform(array $item, $format);
}
然后我有以下类来实现它:
class ServiceLogTransformer extends Transformer {
public function transform(array $service_log, $format = false)
{
return [
'id' => $service_log['id'],
'date' => $service_log['log_date'],
'time' => $service_log['log_time'],
'type' => ($format ? status_label($service_log['log_type']) : $service_log['log_type']),
'entry' => $service_log['log_entry']
];
}
}
当此代码运行时,我收到错误:
array_map():参数 #3 应该是一个数组
在类中调用函数时,如何传递 2 个或更多参数?我检查了PHP文档,看起来这是允许的,但它在我的Larave 4.2项目上不起作用。array_map
有什么想法吗?