PHP fn Keyword

The?fn?keyword 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.

The general syntax of an arrow function is:

fn(arguments) => expression to be returned;


<?php
// This only works in PHP 7.4 and above
$str =?"Hello World";
$my_function = fn($a) => $str . $a;
echo?$my_function("!");
//result: Hello World!
?>        

要查看或添加评论,请登录

Abanoub Makram的更多文章

  • php Null coalescing operator (??)

    php Null coalescing operator (??)

    $x = expr1 ?? expr2; Returns the value of $x. The value of $x is expr1 if expr1 exists, and is not NULL.

社区洞察

其他会员也浏览了