我可以使用array_map替换此代码:
$points = [];
foreach($addresses as $address) $points[] = $address->getRoutePoint();
$this->points = $points;
答案 0 :(得分:0)
没什么特别要做的:
$this->points = array_map(function($i) { return $i->getRoutePoint(); }, $addresses);
但是,使用foreach
的速度更快,您无需使用$points
变量:
$this->points = [];
foreach($addresses as $address) {
$this->points[] = $address->getRoutePoint();
}