Syntax

PHP Arrow Function Syntax

In PHP, arrow function: writes a short anonymous function — $double = fn($x) => $x * 2;

Quick Answer

Syntax
$double = fn($x) => $x * 2;
PHPSyntax

Arrow Function

Code example
$double = fn($x) => $x * 2;

Writes a short anonymous function.

Learn More

How to arrow function in PHP

  1. Open your PHP file or editor.
  2. Copy the example, then replace its sample names and values for your code.

PHP Arrow Function Syntax

Use $double = fn($x) => $x * 2;.

Related Syntax References

Frequently asked questions

What is the PHP syntax for arrow function?

Use this pattern: $double = fn($x) => $x * 2;

Can I copy this PHP code example?

Yes. Use Copy code and adapt the example to your program.

Is this PHP syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify