Finding $i basics

In an attempt to fill in some of my own, more blatant, personal voids with php, I have been searching for info on the $i, (including about what it refers to and its use, etc. As I’ve only barely touched on this before, but now we’re stretching my memory.

like for being applied to:
($i = 0; $i < 10; $i++)

Anything plain and simple that anyone could say about it?

I had always just “assumed” integer, but then what about floats?

Edit, here’s another thought.

If you’re going to nest a loop, what’s your next step of variables?

($i=0; $i<10; $i++)
($i_a=0; $i_a<10; $i_a++)



Ahh, that was off topic. How do you do an “off topic” box?

i, j, k are used quite often in mathematics too.

$j, then $k, etc…

Off Topic:

Using [noparse][ot]{text}[/ot][/noparse] :wink:

An important note about using $i is that its use should be tightly restricted to tracking the loop index. If you’re passing it to a function then that function should call it something more meaningful such as $personIndex. That allows the function to remain more readable than if it was just $i.

Yup. It originated in Fortran, as mentioned by Felgall, where integers started with i -> N and real variables started with the rest. I was the first integer variable name.

Fortran was one of the earliest widespread programming languages, so there is quite a bit that was passed down onto the more ‘modern’ languages.

Before Fortran?
Mathematicians were using i,j,k to designate integers in algebra (subscripts, series, summations etc) long before (e.g 1836 or 1816) computers were around (this is the origin of the FORTRAN variable type defaults).

Yep, it could be anything:

($rebel = 0; $rebel < 10; $rebel++)

$i has no magical characteristics native to the language. Its just an established norm when dealing with for loops.

I have always understood variable i to be short hand for ‘index’ stemming from the days of C and before that, probably. ‘j’ being the next character in the alphabet was frequently used when there was a secondary loop inside the first. k would naturally follow suit.


it’s sort of the ‘standard variable’. Like X in calculus. It could be any letter, any name… the standard is just ‘i’. Perhaps it came from “Iterator”, but there’s no difference between for($i = 0; $i < 10; $i++) and for($antidisistablishmentarianism = 0; $antidisistablishmentarianism < 10; $antidisistablishmentarianism++)

I think you’ll find that using i as the loop control originally comes from Fortran where names starting with i,j,k,l,m and n are integers and everything else is floating point. That makes i the first variable name that could be used.