0

I would calculed the sum the 1 to 10 by for in php,this code is true or false?

<?php for($i=1;$i<=10;$i++){ $i+=$i; } echo "$i"; ?>

3rd Mar 2017, 6:37 AM
lahcen dabouz
lahcen dabouz - avatar
2 Answers
+ 6
Nope... define a variable sum before the loop and set it to zero. add i in the loop to sum. after the loop, output sum. also you don't need the quotation marks in echo if you only want to output a variable.
3rd Mar 2017, 6:44 AM
Mario L.
Mario L. - avatar
0
thinks my friend
3rd Mar 2017, 6:46 AM
lahcen dabouz
lahcen dabouz - avatar