+ 4
Please Explain me this code
It shows 10 as a result But can u guys help me How it it please? Im a complete Noob function func($arg) { $result = 0; for($i=0; $i<$arg; $i++) { $result = $result + $i; } return $result; } echo func(5);
4 Answers
+ 19
The argument 5 is passed to function func
so value of $arg becomes 5 ($arg=5)
for loop runs 5 times for value of $i=0 to $i=4....
the values of $i gets adding in $result
then look up š @brains comment
@subhas FYI:- if u see brains in play section don't challenge šššš
+ 5
1+2+3+4=10
+ 5
0+1+2+3+4 = 10
+ 4
Thx a lot Guys