[nflug] PHP character question

Rob Dege livemotion at gmail.com
Fri Apr 18 12:22:35 EDT 2008


Hello to all,

I am trying to create a simple for loop, but instead of incrementing
numbers, I want to increment characters.  I am able to get the code to work,
up until the end, when it comes time to output the last char.

for ($i = A; $i < Z; $i++)
  {
    echo "$i <br>";
   }

In this simple example, the output would be to echo the characters A - Y,
omitting Z; which is expected.  If I change $i < Z to $i <= Z, one would
expect to have Z included in the output.  Unfortunately, this does not
happen.  Instead, it continues to loop past Z until it outputs YZ (A - Z, AA
- AZ, BA - BZ, ..... YA - YZ).  This would imply that it's matching against
ZA instead of just Z.  I know there are alternate ways around this, but now
I'm really curious about the looping behavior here.  Any insight is
appreciated.


I also have a related question with an if condition, if you want further
head scratching.

if ($i != M || $i != Z) { echo " | "; }

With this statement, whenever $i has the value of either M or Z it should
execute the condition, but it doesn't.  However, if I separate the if
condition into two separate conditions statements, it works as intended.

if ($i != M) { echo " | "; }

if ($i != Z) { echo " | "; }

I'm not sure why the || would cause a problem, but for some reason it does.

-- 
-Rob

Ben Franklin Quote: "They that can give up essential liberty to obtain a
little temporary safety deserve neither liberty nor safety."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.nflug.org/pipermail/nflug/attachments/20080418/2af04e26/attachment.html


More information about the nflug mailing list