If ('a' > 'ZZZZZ') ........guess what the answer is

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zardiw
Forum Newbie
Posts: 8
Joined: Mon Oct 29, 2007 11:29 pm

If ('a' > 'ZZZZZ') ........guess what the answer is

Post by zardiw »

For some reason, this is evaluating as true. I give up........lol.........z

Code: Select all

If ('a' > 'ZZZZZ') {
  Print("a is more than zzzzzs");
  ?><BR><?;
}  


a is more than zzzzzs
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

That's some interesting behavior.

Code: Select all

C:\Users\scott>php -r "var_dump($a = 'a' > 'ZZZZ');"
bool(true)

C:\Users\scott>php -r "var_dump($a = 'a' > 'z');"
bool(false)

C:\Users\scott>php -r "var_dump($a = 'a' > 'Z');"
bool(true)
Seems it's the case that matters.

I imagine a-z is in order of ranking as suspected, where as A ranks slightly below z, and follows from A-Z in the same manner.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Z is lower than a in ascii, and if it's comparing it as a string, a would be greater than Z.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

C:\Users\scott>php -r "$r1 = range('a', 'z'); $r1 = array_merge($r1, $r1); $r2 =
 array_merge(range('a', 'z'), range('A', 'Z')); $i=1; foreach ($r1 AS $r) { echo
 $r > $r2[$i] ? $r . ' is greater than ' . $r2[$i] : $r . ' is less than ' . $r2
[$i]; $i++; }"

a is less than b
b is less than c
c is less than d
d is less than e
e is less than f
f is less than g
g is less than h
h is less than i
i is less than j
j is less than k
k is less than l
l is less than m
m is less than n
n is less than o
o is less than p
p is less than q
q is less than r
r is less than s
s is less than t
t is less than u
u is less than v
v is less than w
w is less than x
x is less than y
y is less than z
z is greater than A
a is greater than B
b is greater than C
c is greater than D
d is greater than E
e is greater than F
f is greater than G
g is greater than H
h is greater than I
i is greater than J
j is greater than K
k is greater than L
l is greater than M
m is greater than N
n is greater than O
o is greater than P
p is greater than Q
q is greater than R
r is greater than S
s is greater than T
t is greater than U
u is greater than V
v is greater than W
w is greater than X
x is greater than Y
y is greater than Z
:)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
zardiw
Forum Newbie
Posts: 8
Joined: Mon Oct 29, 2007 11:29 pm

Post by zardiw »

I was running a while statement. I have a MySql database with the primary key being a stock symbol. The keys are both lower and upper case, so apparently I have to make them all one or the other.........Thanks for the info guys..............z
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

It's called collation sequence. There are different sequences for different languages and even several for the english alphabet. Some databases let you specify the collation sequence for each table, or when you are sorting data. cf: http://en.wikipedia.org/wiki/Collating_sequence and Google it.
zardiw
Forum Newbie
Posts: 8
Joined: Mon Oct 29, 2007 11:29 pm

Post by zardiw »

MySql doesn't care if it's upper or lower case. Some of the keys are part upper and lower.

Somebody said I should use strcasecmp(), but I think I'll just pass the DB and change everything to upper case, and then use strtoupper() when I'm adding new records.......z
zardiw
Forum Newbie
Posts: 8
Joined: Mon Oct 29, 2007 11:29 pm

Post by zardiw »

astions wrote:Z is lower than a in ascii, and if it's comparing it as a string, a would be greater than Z.
The actual compare was

Code: Select all

while $CurrSymb < 'ZZZZZ' {
    do a bunch of crap
}

z
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I'm aware of that. You have most likely implemented your own, albeit more resource intensive, version of MySQL's built in COALESCE function.

Refer to: http://dev.mysql.com/doc/refman/5.0/en/ ... n_coalesce
zardiw
Forum Newbie
Posts: 8
Joined: Mon Oct 29, 2007 11:29 pm

Post by zardiw »

astions wrote:I'm aware of that. You have most likely implemented your own, albeit more resource intensive, version of MySQL's built in COALESCE function.

Refer to: http://dev.mysql.com/doc/refman/5.0/en/ ... n_coalesce
Well I have little control of the implementation on my webhost's server........is there something I can set to use a less resource intensive process?...........z
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

What are you trying to accomplish?
Post Reply