+ 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);

7th Feb 2018, 2:31 PM
subash kumar
subash kumar - avatar
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 😂😂😂😂
7th Feb 2018, 2:39 PM
🌛DT🌜
🌛DT🌜 - avatar
+ 5
1+2+3+4=10
7th Feb 2018, 2:34 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 5
0+1+2+3+4 = 10
7th Feb 2018, 2:41 PM
Aatif Zaidi
Aatif Zaidi - avatar
+ 4
Thx a lot Guys
7th Feb 2018, 2:41 PM
subash kumar
subash kumar - avatar