array-map

Performance of foreach, array_map with lambda and array_map with static function

∥☆過路亽.° 提交于 2019-11-25 20:46:05
What's the performance difference (if there is any) between these three approaches, both used to transform an array to another array? Using foreach Using array_map with lambda/closure function Using array_map with 'static' function/method Is there any other approach? To make myself clear, let's have look at the examples, all doing the same - multiplying the array of numbers by 10: $numbers = range(0, 1000); Foreach $result = array(); foreach ($numbers as $number) { $result[] = $number * 10; } return $result; Map with lambda return array_map(function($number) { return $number * 10; }, $numbers)