Arrow functions were introduced in PHP 7.4 as a more concise syntax for anonymous functions. Both anonymous functions and arrow functions are implemented using the Closure class. Arrow functions have the basic form fn (argument_list) => expr. Arrow functions support the same features as anonymous functions, except that using variables from the parent scope is always automatic. When a variable used in the expression is defined in the parent scope it will be implicitly captured by value. In the following example, the functions $fn1 and $fn2 behave the same way.
$a = 5;
$b = 6;
function multiply($a, $b)
{
return $a * $b;
}
$product = multiply($a, $b);
$a = 5;
$b = 6;
$multiply = fn($a, $b) => $a * $b;
$product = $multiply($a, $b);
LLoadout is your loadout for Laravel, helping you kickstart your development process. Besides this refactoring site we also make some cool packages and video tutorials !
Go to LLoadout on github