Bug #16215 Updated: uasort does not seem to work

From: Date: Fri, 24 May 2002 04:00:06 +0000
Subject: Bug #16215 Updated: uasort does not seem to work
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-8368@lists.php.net to get a copy of this message
ID: 16215 Updated by: php-bugs@lists.php.net Reported By: eved_hashem@lycos.com -Status: Feedback +Status: No Feedback Bug Type: Arrays related Operating System: Unix PHP Version: 4.1.2 New Comment: No feedback was provided for this bug for over a month, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open". Previous Comments: ------------------------------------------------------------------------ [2002-04-23 20:40:18] sniper@php.net This example script works fine for me with PHP 4.2.0: <?php $array=array(); $array[2]['Fator1']=7; $array[2]['Fator2']="NameDiferente"; $array[0]['Fator1']=7; $array[0]['Fator2']="Name"; $array[1]['Fator1']=5; $array[1]['Fator2']="Name"; function Compare($ar1, $ar2) { if ($ar1['Fator1']<$ar2['Fator1']) return -1; else if ($ar1['Fator1']>$ar2['Fator1']) return 1; if ($ar1['Fator2']<$ar2['Fator2']) return -1; else if ($ar1['Fator2']>$ar2['Fator2']) return 1; return 0; } print_r($array); echo "\n"; uasort($array,'Compare'); print_r($array); echo "\n"; ?> ------------------------------------------------------------------------ [2002-04-23 20:34:36] yohgaki@php.net Jeremy and Eved, you need short & complete example. Short & complete example: - has "<?php" and "?>" tag - works as standalone. (i.e. paste code & execute must work) - number of lines should be 30 at most and code must be easy to read. ------------------------------------------------------------------------ [2002-04-23 20:17:31] jeremy@titr.uow.edu.au same problem as mine (see number 16778). To solve the problem pass your array by reference to the function ex: uasort(&$array_to_be_sorted,"yourcmp") Your array $array_to_be_sorted is now sorted ... Don't expect any result returned by the function (for me it returns 1, maybe saying the array has been sorted) ------------------------------------------------------------------------ [2002-03-22 03:58:51] mfischer@php.net Please provide a full copy&paste example ------------------------------------------------------------------------ [2002-03-21 21:18:34] eved_hashem@lycos.com 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.. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=16215&edit=1

« previous php.bugs (#8368) next »