Skip to content
AgileLogics
3 min read

Arrow Functions

Prerequisites: Functions

An arrow function (fn, PHP 7.4+) is a compact, single-expression function that automatically captures variables from the surrounding scope — no explicit use (...) needed, unlike a full closure (covered in Level 2).

$tax = 0.2;
$addTax = fn ($price) => $price * (1 + $tax);

echo $addTax(100); // 120 — $tax is captured automatically

Used constantly with array functions like array_map and array_filter, exactly as seen in the previous lesson.