Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我记得有一次我遇到了一些网站,其中使用 array_sum 和 array_map 函数在一行上执行了 2 个数组项的总和。有谁知道这是怎么做到的吗?
$a=array(1,2,3,4,5); $b=array(0,1,0,1,0); $result=compoundedSinlgeLineFunction($a,$b); $result=array(1,3,3,5,5); //this is what we get
我发现我可能还需要总结 3 个数字,所以我这样做了,但它与上面的解决方案基本相同
$z = array_map('sum', $z, $y, $x); function sum($x, $y, $z=NULL){ if($z) return $x + $y + $z; else return $x + $y; }
$result = array_map("array_sum", $a, $b);