xxxxxxxxxx
<?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));
?>
xxxxxxxxxx
<?php
//you can only use single expression in arrow functions
fn (arguments) => expression;
ex.
$eq = fn ($x, $y) => $x == $y;
echo $eq(100, '100');
xxxxxxxxxx
$numbers = [1,2,3];
$modifier = 5;
array_map(fn($x) => $x * $modifier, $numbers);
xxxxxxxxxx
arrow operator(->): It is an access operator used to access data members and
methods in a class. It is the same as the (.) operator which we use in
javascript, c++.