// Arrow functions were added for PHP 7.4+
$y = 1;
// this arrow function:
$fn1 = fn($x) => $x + $y;
// is equivalent to using $y by value:
$fn2 = function ($x) use ($y) {
return $x + $y;
};
<?php
//you can only use single expression in arrow functions
fn (arguments) => expression;
ex.
$eq = fn ($x, $y) => $x == $y;
echo $eq(100, '100');
<?php
$y = 1;
$fn1 = fn($x) => $x + $y;
// equivalent to using $y by value:
$fn2 = function ($x) use ($y) {
return $x + $y;
};
var_export($fn1(3));
?>
$numbers = [1,2,3];
$modifier = 5;
array_map(fn($x) => $x * $modifier, $numbers);