Re: When is "z" != "z" ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



tedd wrote:
-TG:

Thanks for your explanation and time.

Normally, I don't alpha++ anything -- not to criticize others, but to me it doesn't make much sense to add a number to a character.  But considering the php language is so string aware, as compared to other languages, I just tried it on a lark just to see what would happen.

Okay, so I found out it's limitations and quirks.

But, you must admit that it is confusing to have a loop that goes from "a" to "z" and considers "aa" but not "aaa".

Now, if the loop just went from a to z, then I would think that would be logical. But I fail to see the logic behind considering "aa" but not "aaa" in the evaluation. But then again, I'm not that informed.

Enough said.

tedd



At 12:21 PM -0400 6/5/06, <tg-php@xxxxxxxxxxxxxxxxxxxxxx> wrote:
I know this discussion doesn't need to continue any further..hah.. but I think the biggest confusion people are having is that they're looking at two things and assuming that PHP operates the same on both and these two things serve different purposes.

1. Incrementing strings: Best example giving was "File1"++ == "File2" or "FileA"++ == "FileB".  In that case, wouldn't you want it to go from FileZ to FileAA?  Makes sense right?

2. Comparing "greatness" of strings:  Rasmus mentioned this earlier, but I wante to illustrate it a little more because I think it was overlooked.  If you have a list of names, for instance, and you alphabetize them, you'd get something like this:

Bob
Brendan
Burt
Frank
Fred

Just become a name is longer doesn't mean it comes after the rest of the names in the list.  So in that vane, anything starting in "A" will never be > something starting with a "Z".  a < z  aa < z  aaa < z because:

a
aa
aaa
z

When using interation and a for loop and " <= z" it gets to "y" and it's true, gets to "z" and it's still true, then increments to "az" and yup.. still < "z".  As mentioned, it's not until you get to something starting in "z" with something after it that you're > "z".

So hopefully that makes a little more sense.

-TG



= = = Original message = = =

tedd wrote:
At 1:09 PM -0700 6/4/06, Rasmus Lerdorf wrote:
I agree with [1] and [2], but [3] is where we part company. You see, if you are right, then "aaa" would also be less than "z", but that doesn't appear so.
Of course it is.

php -r 'echo "aaa" < "z";'
1
You missed the point, why does --

for ($i="a"; $i<="z"; $i++)
echo($i);
-- not continue past "aaa"? Clearly, if "aaa" is less than "z" then why does the loop stop at "yz"?
I thought I explained that a few times.  The sequence is:

a b c ... x y z aa ab ac ... yx yy yz za zb zc ... zy zx zz aaa aab

Your loop stops at yz and doesn't get anywhere near aaa because za > z

-Rasmus


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

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



As mentioned before, discussion aside, you can do what you want with range and a foreach:

foreach (range('a', 'z') as $char)
{
   echo $char;
}

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux