Last active
February 9, 2022 13:56
-
-
Save noweh/89d4a791a82ac9a8f5dbffa96ef6a85d to your computer and use it in GitHub Desktop.
Example of using PHP Arrow functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$foo = 'foo'; | |
$functions = [ | |
'function1' => function ($bar) use ($foo) { | |
return $foo . $bar; | |
}, | |
'function2' => fn ($bar) => $foo . $bar | |
]; | |
foreach ($functions as $function) { | |
echo $function("bar"); | |
// will output "foobar" twice | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment