Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default amazing for loop

    Hi all,

    I tried this :
    for( $i = 'M' ; $i <= 'Y' ; $i++) {
    $alpha_2 .= $i."&nbsp;&nbsp;&nbsp;" ;
    }
    I get :
    M N O P Q R S T U V W X Y
    => no problem

    BUT !
    Try this :
    for( $i = 'M' ; $i <= 'X' ; $i++) {
    $alpha_2 .= $i."&nbsp;&nbsp;&nbsp;" ;
    }
    I get :
    M N O P Q R S T U V W X Y Z AA AB AC AD
    AE AF AG AH AI AJ AK AL AM AN AO AP AQ AR AS
    AT AU AV AW AX AY AZ BA BB BC BD BE BF BG BH
    BI BJ BK BL BM BN BO BP BQ BR BS BT BU BV BW
    BX BY BZ CA CB CC CD CE CF CG CH CI CJ CK CL
    CM CN CO CP CQ CR CS CT CU CV CW CX CY CZ DA
    DB DC DD DE DF DG DH DI DJ DK DL DM DN DO DP
    DQ DR DS DT DU DV DW DX DY DZ EA EB EC ED EE
    EF EG EH EI EJ EK EL EM EN EO EP EQ ER ES ET
    EU EV EW EX EY EZ FA FB FC FD FE FF FG FH FI
    FJ FK FL FM FN FO FP FQ FR FS FT FU FV FW FX
    FY FZ GA GB GC GD GE GF GG GH GI GJ GK GL GM
    GN GO GP GQ GR GS GT GU GV GW GX GY GZ HA HB
    HC HD HE HF HG HH HI HJ HK HL HM HN HO HP HQ
    HR HS HT HU HV HW HX HY HZ IA IB IC ID IE IF
    IG IH II IJ IK IL IM IN IO IP IQ IR IS IT IU
    IV IW IX IY IZ JA JB JC JD JE JF JG JH JI JJ
    JK JL JM JN JO JP JQ JR JS JT JU JV JW JX JY
    JZ KA KB KC KD KE KF KG KH KI KJ KK KL KM KN
    KO KP KQ KR KS KT KU KV KW KX KY KZ LA LB LC
    LD LE LF LG LH LI LJ LK LL LM LN LO LP LQ LR
    LS LT LU LV LW LX LY LZ MA MB MC MD ME MF MG
    MH MI MJ MK ML MM MN MO MP MQ MR MS MT MU MV
    MW MX MY MZ NA NB NC ND NE NF NG NH NI NJ NK
    NL NM NN NO NP NQ NR NS NT NU NV NW NX NY NZ
    OA OB OC OD OE OF OG OH OI OJ OK OL OM ON OO
    OP OQ OR OS OT OU OV OW OX OY OZ PA PB PC PD
    PE PF PG PH PI PJ PK PL PM PN PO PP PQ PR PS
    PT PU PV PW PX PY PZ QA QB QC QD QE QF QG QH
    QI QJ QK QL QM QN QO QP QQ QR QS QT QU QV QW
    QX QY QZ RA RB RC RD RE RF RG RH RI RJ RK RL
    RM RN RO RP RQ RR RS RT RU RV RW RX RY RZ SA
    SB SC SD SE SF SG SH SI SJ SK SL SM SN SO SP
    SQ SR SS ST SU SV SW SX SY SZ TA TB TC TD TE
    TF TG TH TI TJ TK TL TM TN TO TP TQ TR TS TT
    TU TV TW TX TY TZ UA UB UC UD UE UF UG UH UI
    UJ UK UL UM UN UO UP UQ UR US UT UU UV UW UX
    UY UZ VA VB VC VD VE VF VG VH VI VJ VK VL VM
    VN VO VP VQ VR VS VT VU VV VW VX VY VZ WA WB
    WC WD WE WF WG WH WI WJ WK WL WM WN WO WP WQ
    WR WS WT WU WV WW WX WY WZ XA XB XC XD XE XF
    XG XH XI XJ XK XL XM XN XO XP XQ XR XS XT XU
    XV XW XX XY XZ YA YB YC YD YE YF YG YH YI YJ
    YK YL YM YN YO YP YQ YR YS YT YU YV YW YX YY
    YZ
    => hum... what's the problem ?

    any idea ?

    thanks in advance,
    --
    nyso


    nyso Guest

  2. Similar Questions and Discussions

    1. ! Amazing Jobs
      Check this out : http://linkbee.com/AJEG
    2. The amazing repeating event!
      Okay, I'm still working on the problem I've been on for three days. I have a call to main.asc and it returns a string. (I only care that it...
    3. Oh my god... this is absolutely AMAZING Flash...
      Eminem's latest video is entirely in Flash ... unfreaking believable. Regardless of whether you like his music, you owe it to yourself as a Flash...
    4. Amazing effect
      Right i was just looking through some web sites and this effect cought my eye which i would like to know how to make!!! If you go to...
    5. AMAZING FLASH!
      I think mine is pretty good. If you want a continually updated list of the best around go to... http://www.favouritewebsiteawards.com/home.html ...
  3. #2

    Default Re: amazing for loop - erratum

    > for( $i = 'M' ; $i <= 'X' ; $i++) {
    > $alpha_2 .= $i."&nbsp;&nbsp;&nbsp;" ;
    > }
    I meant :
    > for( $i = 'M' ; $i <= 'Z' ; $i++) {
    sorry !
    --
    nyso


    nyso Guest

  4. #3

    Default Re: amazing for loop

    *** nyso wrote/escribió (Thu, 20 Nov 2003 09:56:27 +0100):
    > for( $i = 'M' ; $i <= 'Y' ; $i++) {
    'X' <= 'Y' ? --> true
    'Y' <= 'Y' ? --> true
    'Z' <= 'Y' ? --> false --> end

    'X' <= 'Z' ? --> true
    'Y' <= 'Z' ? --> true
    'Z' <= 'Z' ? --> true
    'AA' <= 'Z' ? --> true
    'AB' <= 'Z' ? --> true
    ....
    'YY' <= 'Z' ? --> true
    'YZ' <= 'Z' ? --> true
    'ZA' <= 'Z' ? --> false --> end

    Please note you aren't comparing numbers but strings.


    --
    --
    -- Álvaro G. Vicario - Burgos, Spain
    --
    Alvaro G Vicario Guest

  5. #4

    Default Re: amazing for loop

    On Thu, 20 Nov 2003 11:48:31 +0100, Alvaro G Vicario
    <alvaro_QUITAR_REMOVE@telecomputeronline.com> wrote:
    >*** nyso wrote/escribió (Thu, 20 Nov 2003 09:56:27 +0100):
    >> for( $i = 'M' ; $i <= 'Y' ; $i++) {
    >
    >'X' <= 'Y' ? --> true
    >'Y' <= 'Y' ? --> true
    >'Z' <= 'Y' ? --> false --> end
    >
    >'X' <= 'Z' ? --> true
    >'Y' <= 'Z' ? --> true
    >'Z' <= 'Z' ? --> true
    >'AA' <= 'Z' ? --> true
    >'AB' <= 'Z' ? --> true
    >...
    >'YY' <= 'Z' ? --> true
    >'YZ' <= 'Z' ? --> true
    >'ZA' <= 'Z' ? --> false --> end
    >
    >Please note you aren't comparing numbers but strings.
    It is interesting to see that PHP considers 'Z' + 1 == 'AA', though.

    --
    David ( @priz.co.uk )
    The Internet Prisoner Database: [url]http://www.priz.co.uk/ipdb/[/url]
    The Tarbrax Chronicle: [url]http://www.tarbraxchronicle.com/[/url]
    David Mackenzie Guest

  6. #5

    Default Re: amazing for loop

    David Mackenzie wrote:
    > It is interesting to see that PHP considers 'Z' + 1 == 'AA', though.
    Interesting yes, but I think that it is nice that PHP doesn't base
    incrementing a string solely on the ASCII value. Afterall, I think that
    the following is a natural progression..

    A,B...
    Y,Z,AA,AB...
    AY,AZ,BA,BB...
    ZY,ZZ,AAA...

    Afterall, when incrementing a character by adding int(1) to it, you are
    simply increasing the ASCII value. After "Z" (chr(90)) would be "["
    (chr(91)).

    Also beware that ord('AA') will return 65 since it returns the ASCII
    value of the *first* character of the string.

    --
    Justin Koivisto - [email]spam@koivi.com[/email]
    PHP POSTERS: Please use comp.lang.php for PHP related questions,
    alt.php* groups are not recommended.

    Justin Koivisto Guest

  7. #6

    Default Re: amazing for loop

    On Thu, 20 Nov 2003 15:12:51 GMT, Justin Koivisto <spam@koivi.com>
    wrote:
    >David Mackenzie wrote:
    >> It is interesting to see that PHP considers 'Z' + 1 == 'AA', though.
    >
    >Interesting yes, but I think that it is nice that PHP doesn't base
    >incrementing a string solely on the ASCII value. Afterall, I think that
    >the following is a natural progression..
    >
    >A,B...
    >Y,Z,AA,AB...
    >AY,AZ,BA,BB...
    >ZY,ZZ,AAA...
    I've just noticed that it is following exactly the same algorithm as
    for incrementing "numeric" strings ("8", "9", "10", "11") except using
    ASCII ranges 65..90 as opposed to 48..57.

    I was once writing a function to concatenate date parts together
    (before I discovered the date functions). I had:

    $day = 19;
    $month = "March";
    $year = 1928;

    The result of
    $date = $day." ".$month." ".$year;

    was
    $date == "1947 March"

    It added 19 and 1928, but preserved "March".

    --
    David ( @priz.co.uk )
    The Internet Prisoner Database: [url]http://www.priz.co.uk/ipdb/[/url]
    The Tarbrax Chronicle: [url]http://www.tarbraxchronicle.com/[/url]
    David Mackenzie Guest

  8. #7

    Default Re: amazing for loop

    *** David Mackenzie wrote/escribió (Thu, 20 Nov 2003 11:36:54 +0000):
    > It is interesting to see that PHP considers 'Z' + 1 == 'AA', though.
    It is curious indeed. It's documented anyway:

    «PHP follows Perl's convention when dealing with arithmetic operations on
    character variables and not C's. For example, in Perl 'Z'+1 turns into
    'AA', while in C 'Z'+1 turns into '[' ( ord('Z') == 90, ord('[') == 91 ).
    Note that character variables can be incremented but not decremented.»

    [url]http://us2.php.net/manual/en/language.operators.increment.php[/url]

    (Nope, I didn't know until today ;-)


    --
    --
    -- Álvaro G. Vicario - Burgos, Spain
    --
    Alvaro G Vicario Guest

  9. #8

    Default Re: amazing for loop

    Alvaro G Vicario wrote:
    >
    > *** David Mackenzie wrote/escribió (Thu, 20 Nov 2003 11:36:54 +0000):
    > > It is interesting to see that PHP considers 'Z' + 1 == 'AA', though.
    >
    > It is curious indeed. It's documented anyway:
    >
    > «PHP follows Perl's convention when dealing with arithmetic operations on
    > character variables and not C's. For example, in Perl 'Z'+1 turns into
    > 'AA', while in C 'Z'+1 turns into '[' ( ord('Z') == 90, ord('[') == 91 ).
    > Note that character variables can be incremented but not decremented.»

    Actually, C guarantees nothing of the sort. It does not require the use
    of the ASCII character set at all, and in fact some implementations do
    not use it. The result of 'Z'+1 is entirely implementation-specific.

    The a more correct form of the statement would be something like, "while
    in strict ASCII systems, such as some implementations of C, 'Z'+1 turns
    into '[' . . ."



    Brian Rodenborn
    Default User Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139