PHP News (Sort Closure)
PHP 7.4 Short Closure
Short closures, also called arrow functions, are a way of writing shorter functions in PHP. This notation is useful when passing closures to functions like
array_map
or
array_filter.
Current usage
// A collection of Post objects
$posts = [/* … */];
$ids = array_map(fn($post) => $post->id, $posts);
Before
$ids = array_map(function ($post) {
return $post->id;
}, $posts);