Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用带有回调函数的数组映射作为数组元素的成员?_Php - Fatal编程技术网

Php 如何使用带有回调函数的数组映射作为数组元素的成员?

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

我是否可以使用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();
}

没有什么特别要做的:

$this->points = array_map(function($i) { return $i->getRoutePoint(); }, $addresses);
但是,使用
foreach
更快,并且不需要使用
$points
变量:

$this->points = [];
foreach($addresses as $address) {
    $this->points[] = $address->getRoutePoint();
}