Externa variabler i arrow-funktioner i PHP
I en arrow-funktion är externa variabler tillgängliga automatiskt:
php<?php
$num1 = 1;
$num2 = 2;
$func = fn() => $num1 + $num2;
echo $func(); // 3
?>
Задание 1
Skriv om följande kod med en arrow-funktion:
php<?php
$num1 = 1;
$num2 = 2;
$func = function() use ($num1, $num2)
{
echo $num1 + $num2;
};
$func();
?>