View Full Version : $i means what?
Temper
06-08-2003, 03:46 PM
I'm learning PHP+MySQL out of this fat book, and all the chapters on MySQL Databasing have this little variable that I just can't figure out what it is. I'm constantly seeing things like $i=0, $i<=, $i+, $i++, but I don't know what $i is. I understand all the signes ( ++, <=, == ) but I don't see why I have to use $i. Does this variable have a name, and what's it's function?
Thank you
~Mike
whackaxe
06-08-2003, 04:32 PM
sounds like the classic for() loop the basic syntax is this
for ($i = 0, $i<10, $i++)
{
print($i);
}
now what this does is a loop. first off it looks at the first argument: $i = 0 sets the variable $i to 0. why use "i"? its just a way things went with programming over time. you could use anything else, but alot of people just use i cos thats the way they ere taught.
next argument: $i<10. that check the variable $i to see if its smaller than 10. in this case.....
.....$i++ adds 1 to $i
that is the most common for loop but you could of course make an infinte loop if you left out $i++
hope that(unclear) explanation helps
Galdo
06-08-2003, 04:33 PM
Originally posted by Temper
$i=0, $i<=, $i+, $i++
A variable called $i is used a lot for 'for' loops and what not because its quick to type I guess. Yes, you can use any other letter or word for that matter. As far as I know there is no special reason for using $i other than the speed of typing it, so $a or $elephant would also work.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.