我可以使用array_map替换此代码:
$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();
}