Php Arrow Function

As of php7.4, php arrow function was added as a more concise syntax for anonymous functions.

Basic syntax:

1fn (arguments) => expression;

Is functionally equivalent to the following anonymous function:

1function(arguments) { return expression; }

Unlike anonymous functions, arrow functions can automatically access variables from their parent scopes.

 1<?php
 2
 3function multiplier($x)
 4{
 5    return fn ($y) => $x * $y;
 6}
 7
 8$double = multiplier(2);
 9
10echo $double(10); // 200

See also https://ismael.casimpan.com/quicktasks/php-anonymous-function/

Reference: