PHP fn Keyword

PHP for Keyword
PHP finally Keyword

In this article, you will learn how to create an arrow function in PHP. The fn keyword in PHP is used to create arrow functions. Arrow functions are only available in PHP versions 7.4 and up. Arrow functions have access to all variables from the scope in which they were created.

what is the syntax of the arrow function in Php?

fn(arguments) => expression to be returned;

examples of the FN keyword

Example 1. In this example, we create an arrow function.

<?php
// This only works in PHP 7.4 and above
$str = "Hello World";
$my_function = fn($a) => $str . $a;
echo $my_function("!");
?>
PHP for Keyword
PHP finally Keyword
en English
X
Scroll to Top