+ 1
PHP Help with function and for combined
I got this question in a test, with the advice o clues I got an answer of 10 but I did not get it, somebody can help me step by step? What output results from the following code? function func($arg) { $result = 0; for($i=0; $i<$arg; $i++) { $result = $result + $i; } return $result; } echo func(5);
1 Answer
+ 2
It's adding the numbers from 0 to $arg-1. In this case $arg == 5.
1+2+3+4 == 10.



