<?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";
?>
<?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";
?>
转载于:https://www.cnblogs.com/tiantian123/p/5724017.html