Introduction
Arrow functions let you write small functions quickly and clearly without extra words.
fn (argument_list) => expression;
$double = fn($x) => $x * 2;$sum = fn($a, $b) => $a + $b;
$greet = fn($name) => "Hello, $name!";<?php $numbers = [1, 2, 3, 4]; $double = fn($x) => $x * 2; $doubledNumbers = array_map($double, $numbers); print_r($doubledNumbers);
$factor = 3;
$multiply = fn($x) => $x * $factor;
echo $multiply(5);
$a = 10;
$fn = fn($x) => { return $x + $a; };
echo $fn(5);
$numbers = [2, 4, 5, 7, 1];
// Fill in the blanks:
$filtered = array_filter($numbers, fn($n) => ________);
$doubled = array_map(fn($n) => ________, $filtered);
print_r($doubled);
Pass the test and this pattern moves unknown