RosettaCodeData/Task/Accumulator-factory/PHP/accumulator-factory-1.php
2013-04-10 14:58:50 -07:00

8 lines
198 B
PHP

<?php
function accumulator($start){
return create_function('$x','static $v='.$start.';return $v+=$x;');
}
$acc = accumulator(5);
echo $acc(5), "\n"; //prints 10
echo $acc(10), "\n"; //prints 20
?>