RE: [PHP] A to Z incremental
| From: | electroteque | Date: | Fri, 23 Apr 2004 11:41:39 +0000 |
| Subject: | RE: [PHP] A to Z incremental | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-184381@lists.php.net to get a copy of this message | ||
use the chr($i) system
> -----Original Message-----
> From: Ford, Mike [LSS] [mailto:M.Ford@leedsmet.ac.uk]
> Sent: Friday, April 23, 2004 9:31 PM
> To: 'Paul'; php-general@lists.php.net
> Subject: RE: [PHP] A to Z incremental
>
>
> On 22 April 2004 15:22, Paul wrote:
>
> > Hi!
> > Got this script:
> >
> > <?php
> > for($i='A';$i<='Z';$i++){ echo $i.' | '; }
> > >
> >
> > The output is:
> > A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P
> > > Q | R | S | T | U | V | W | X | Y | Z |
> > AA | AB | AC |
> > ...
> > YX | YY | YZ |
> >
> > where is should display only letters from A to Z.
> > Why is that?
>
> Because 'Z'++ (if you see what I mean!) is 'AA'.
>
> (So, at the end of the loop iteration which echoes 'Z', $i becomes 'AA',
> which is <'Z', and as a result the loop continues on through all
> the values
> you saw. The loop terminates after 'YZ' is echoed, since at the
> end of that
> iteration $i increments to 'ZA', which is not <'Z', and Bob's your
> uncle!)
>
> One way of solving this is:
>
> for ($i='A'; $i!='AA'; $i++)
>
> 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: m.ford@leedsmet.ac.uk
> 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