Php 如何使用带有回调函数的数组映射作为数组元素的成员?
我是否可以使用array_map替换此代码:Php 如何使用带有回调函数的数组映射作为数组元素的成员?,php,Php,我是否可以使用array_map替换此代码: $points = []; foreach($addresses as $address) $points[] = $address->getRoutePoint(); $this->points = $points; 没有什么特别要做的: $this->points = array_map(function($i) { return $i->getRoutePoint(); }, $addresses); 但是,使用fo
$points = [];
foreach($addresses as $address) $points[] = $address->getRoutePoint();
$this->points = $points;
没有什么特别要做的:
$this->points = array_map(function($i) { return $i->getRoutePoint(); }, $addresses);
但是,使用foreach
更快,并且不需要使用$points
变量:
$this->points = [];
foreach($addresses as $address) {
$this->points[] = $address->getRoutePoint();
}
没有什么特别要做的:
$this->points = array_map(function($i) { return $i->getRoutePoint(); }, $addresses);
但是,使用foreach
更快,并且不需要使用$points
变量:
$this->points = [];
foreach($addresses as $address) {
$this->points[] = $address->getRoutePoint();
}