On 19 November 2003 14:25, Jay Blanchard contributed these pearls of wisdom:

> [snip]
> for ($letter = 'A'; $letter++; $letter <= 'Z')
>  echo "<a
> href=\"?action=alphabet&letter=$letter\">$letter</a>\n";
> [/snip]  
> 
> I tested this and found two small problems. The code works if
> you do this (I was myself amazed that letters would increment)

Well, it's mentioned (briefly) in the manual
(http://uk.php.net/manual/en/language.operators.increment.php), so maybe you
shouldn't be so amazed.

> 
> for($letter = 'A'; $letter < 'Z'; $letter++){
>       echo $letter . "\n";
> }
> 
> The problem seems to be that you cannot use <='Z' for some
> reason, as the array becomes quite lengthy, as if 'Z' doesn't
> work properly.

The problem is not that 'Z' doesn't work "properly", but that that PHP's
idea of "properly" is different from yours: 'Z'+1 is defined to be 'AA' (it
says that in the manual, too!), so your loop has to be:

  for($letter = 'A'; $letter <= 'AA'; $letter++){
        echo $letter . "\n";
  }

Cheers!

Mike

-- 
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to