<?php
function func($a, $b) {
$line = function ($x) use ($a, $b) {
return $a*$x + $b;
};
return $line;
}
$line1 = func(1, 1);
$line2 = func(3, 4);
$x = 5;
$y1 = $line1($x);
$y2 = $line2($x);
echo "x=$x ---> y1=$y1 , y2=$y2";
?>
2022-10-23 11:11:01
<?php
function func($a, $b) {
$line = function ($x) use ($a, $b) {
return $a*$x + $b;
};
return $line;
}
$line1 = func(1, 1);
$line2 = func(3, 4);
$x = 5;
$y1 = $line1($x);
$y2 = $line2($x);
echo "x=$x ---> y1=$y1 , y2=$y2";
?>