Unexpected results using ksort on arrays in which the keys are mixed alphanumeric strings.

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

 



I have been experimenting using four character alphanumeric keys on an array, and when I
generated a random set of keys, and then used ksort to sort the array, I was very
surprised to find that if the key contained any non-numeric character, or if it started
with zero, the key was sorted as a base 36 number (0- 9, A-Z, as I expected. However if
the key only contained numbers, and did not start with zero, it was sorted to the end of
the list.

Thus:
	0000
	0009
	000A

	0999
	09A0
	ASDF

	ZZZZ
	1000
	9999

I presume this is related to last weeks discussions about casting variables, but I cannot
understand why 0999 should go to the start of the list, while 1000 goes to the end. Can
anyone explain this logically?

-- 
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