Arrow functions also called “short closures”. We can always access the parent scope, there’s no need for the use keyword. Here is a simple example with an arrow function.
1 2 3 |
$items = [1,2,3,4,5]; $factor = 10; array_map(fn ($item) => $item * $factor, $items) |
Above code we can write as show below without arrow function
1 2 3 4 |
$items = [1,2,3,4,5]; array_map(function ($item) use ($factor) { return $item* $factor; }, $items) |
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.
Subscribe
Login
0 Comments