Jump to content

What Is The Difference Between $I++ And $I+=1


shad

Recommended Posts

<?phpfor($i=0;$i<=10;$i++){$a=$i;echo $a."<br>";}echo $i?>

i got output as

01234567891011

1) question 1) why am i getting 11 after

echo $i

this outside for loop;question 2) I got the same out put when I write

$i+=1

so is can $i++ replace Si+=1 and viceversa

Link to comment
Share on other sites

1) when $i is 10 it got incrementd by $i++ so it become 11 and after tha it check the c0nditi0n $i<=10 and it returns false so it come out of lo0p. But at that time $i is still 11 so when you echo it outside of l0op it shows u 112) $i++ and i+=1 is same

Link to comment
Share on other sites

You get values from 0 to 11 because you start your counter to 0 and finish it when it equals 10. There are 11 numbers from 0-10.

Link to comment
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...