[UPHPU] Understanding php's logic

Jacob Fugal jacob at fugal.net
Tue Apr 6 14:11:26 MDT 2004


Ashley Oviatt wrote:
>  From the php.net site: 
> (http://us3.php.net/manual/en/control-structures.for.php)
> ----------------------------------------------------------
> 
> for ($i="A"; $i <= "Z"; $i++) echo "$i<br>";
> 
> will actually output A-Z, then begin again with AA, AB, etc. until it 
> finishes with YZ.
> 
> ----------------------------------------------------------
> 
> Ok, this seems weird to me for some reason. Why doesn't the loop stop 
> when it reaches the character Z? If you put in a Y in place of the Z, it 
> stops at Y.
> 
> Why does it do this?

Because

1) "Z" <= "Z"
2) "Z"++ == "AA"
3) "AA" <= "Z", so it keeps going.

When you get to "YZ", "YZ"++ == "ZZ" and "ZZ" > "Z", so it stops. 
Replacing  "Z" with "Y",

1) "Y" <= "Y"
2) "Y"++ == "Z"
3) "Z" > "Y", so it stops right there.

Jacob Fugal




More information about the UPHPU mailing list