ID:               27142
 User updated by:  tomas dot matousek at matfyz dot cz
 Reported By:      tomas dot matousek at matfyz dot cz
-Status:           Bogus
+Status:           Open
 Bug Type:         Zend Engine 2 problem
 Operating System: WinXP
 PHP Version:      5.0.0b3 (beta3)
 New Comment:

Well, I can choose another sorting type by the 2nd argument.
But that doesn't solve the problem with the less-than (greater-than)
operator. This operator is supposed to be transitive in common
programming languages.
But in PHP it is not:

"101a" < "6" ... string comparison
"6" < "100" ... numerical comparison
"100" < "101a" ... string comparison

So I get the result "101a" < "101a" which is nonsense.
The non-transitivity obviously cause the problem with sorting which
I've reported.

Maybe it is intended behavior but there is no mention about it in the
documentation.


Previous Comments:
------------------------------------------------------------------------

[2004-02-04 19:29:56] [EMAIL PROTECTED]

See http://www.php.net/asort and notice the 2nd option for this
function. Then see http://www.php.net/sort what values it accepts. Then
try those values. Then fix your own compare function.


------------------------------------------------------------------------

[2004-02-04 06:54:13] tomas dot matousek at matfyz dot cz

Description:
------------
The way in which elements of an array are compared is inconsistent.


Reproduce code:
---------------
    $a = $c = array("101a","100","6");
    $b = $d = array("100","6","101a");

    // standard comparison:
    $f = create_function('$a,$b','return ($a<$b) ? -1:($a>$b ?
+1:0);');
    
    asort($a);
    asort($b);
    uasort($c,$f);
    uasort($d,$f);
    
    print_r($a);
    print_r($b);
    print_r($c);
    print_r($d);


Expected result:
----------------
Than I would expect all 'print_r' print arrays with the same order of
values. 
I would expect that items implicitly converted into numbers during
comparison should precede those of type string.

Actual result:
--------------
Array
(
    [2] => 6
    [1] => 100
    [0] => 101a
)
Array
(
    [2] => 101a
    [1] => 6
    [0] => 100
)
Array
(
    [2] => 6
    [1] => 100
    [0] => 101a
)
Array
(
    [2] => 101a
    [1] => 6
    [0] => 100
)



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=27142&edit=1

Reply via email to