On Sun, Oct 19, 2003 at 11:58:56PM +1000, Wang Feng wrote:
: 
: I don't understand why the decimal 18 is greater than a string like "large"
: in the ascii code? When I  run the following code, the decimal 18 is stored
: in the $third, not the $first. I reckond decimal 18 should be stored into
: the $first after the sorting although it's not. What do you reckond? And how
: come this happen? Please help.
: 
: *******************************
:  $info = array("large", "blue", 18.00);
:  sort($info);
:  list($first, $second, $third) = $info;
:  echo $first, "<br>";
:  echo $second, "<br>";
:  echo $third, "<br>";
: ********************************

Hi Feng,

The problem is that the 3rd element in your array might look like the
string "18.00", but it's actually a floating point number.  Moreover,
how it is represented internally by PHP is platform dependent.

Now if you replaced the floating point number 18.00 with the string
"18.00", now the sorting will be done by ASCII code and you'll get
results that you probably wanted.

        $info = array("large", "blue", "18.00");
        sort($info);
        print_r($info);


-- 
Eugene Lee
eugene at fsck dot net

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

Reply via email to