如题:
请实现一个方法得到两数相加结果,可用以下两种调用方式:
sum(2,3)输出5
sum(2)(3)输出5
sum(2)(3)(4) 输出9
```php
<?php
$a=0;
$s = function($v) use (&$a){
$a+=$v;
};
$sum = function (...$nums) use ($s,&$sum){
foreach ($nums as $v) {
$s($v);
}
return $sum;
};
$sum(3,4)(3)(4)(3,1);
echo $a;
```
#17
更多评论