|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-12-18 17:03 UTC] jan at horde dot org
If you call uasort with a function that always returns 0 (elements equal) you get a totally screwed array returned.
<?php
function mysort($a, $b)
{
return 0;
}
$a = array('h', 's', 'i', 'c', 'q', 'm');
var_dump($a);
uasort($a, 'mysort');
var_dump($a);
?>
returns:
array(6) {
[0]=>
string(1) "h"
[1]=>
string(1) "s"
[2]=>
string(1) "i"
[3]=>
string(1) "c"
[4]=>
string(1) "q"
[5]=>
string(1) "m"
}
array(6) {
[1]=>
string(1) "s"
[2]=>
string(1) "i"
[3]=>
string(1) "c"
[4]=>
string(1) "q"
[5]=>
string(1) "m"
[0]=>
string(1) "h"
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 16 20:00:01 2025 UTC |
I just want to report that the example code for the uasort function in the PHP manual does not work and nothing gets sorted.. I've tried for hours and using multiple books to get uasort to work with multidimensional associative arrays and I have had no success... Am I possibly printing out the arrays incorrectly?? This is what i Used to display the sorted array in the example in the PHP manual: for ( $row = 0; $row < 3; $row++ ) { while (list($key, value) = each ($array[ $row] ) ) { echo "|$value"; } echo "|<BR>"; } this can be the only possible thing I find that could be wrong.. if my code is not incorrect than this is a bug in the program..