Function and arrow function

A named, reusable piece of code; fn() => is a one-line short form.

Also called: closure, fn, callable, anonymous function

Domain
Languages
Type
Term
Source
General
Language
PHP

Example

The function slug("Hello Bali") returns "hello-bali".

In code

function slug(string $text): string {
    return strtolower(trim(preg_replace('/[^a-z0-9]+/i', '-', $text), '-'));
}

$double = fn (int $x) => $x * 2;

Learn more

Related terms

Added 2026-11-30 · Last reviewed 2026-11-30