Hello to all! There is such a code

function cmp($a, $b) { if ( (int)$a < (int)$b ) return -1; if ( (int)$a = (int)$b ) return 0; if ( (int)$a > (int)$b ) return 1; } $s = array(1,1,1,0,0,1,1,1); uasort( $s, cmp ); 

Produces "Array ([5] => 1 [6] => 1 [7] => 1 [4] => 0 [3] => 0 [1] => 1 [2] => 1 [0] = > 1) "Why does the sorting fail? What cant?

PS Until now, did not go to bed, so that the head tupit. I suspect that the error is somehow obvious, but I can’t catch it anymore, I hope for your attention =)

    1 answer 1

     //if ((int)$a = (int)$b) if ((int)$a == (int)$b) 

    =)

    • By the way, why is function cmp($a, $b){return $a - $b;} bad? - ling
    • For int, it seems to be nothing, just the result is just a sign that checks, as I understand it. - Sh4dow
    • I see. Thanks. Although I found one thing here: the function should return an int, so there may be problems with the float. Solved by the gmp_sign function. - ling
    • Thank you) The example once again proves that a healthy sleep is more useful for the project than a couple of extra hours to debug =) - Gorini4