|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16215 uasort does not seem to work
Submitted: 2002-03-21 21:18 UTC Modified: 2002-05-24 00:00 UTC
Avg. Score:2.5 ± 1.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: eved_hashem at lycos dot com Assigned:
Status: No Feedback Package: Arrays related
PHP Version: 4.1.2 OS: Unix
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: eved_hashem at lycos dot com
New email:
PHP Version: OS:


 [2002-03-21 21:18 UTC] eved_hashem at lycos dot 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..


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-22 03:58 UTC]
Please provide a full copy&paste example
 [2002-04-23 20:17 UTC] jeremy at titr dot uow dot edu dot 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-04-23 20:34 UTC]
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:40 UTC]
This example script works fine for me with PHP 4.2.0:



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;

echo "\n";


echo "\n";


 [2002-05-24 00:00 UTC] php-bugs at lists dot php dot net
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".
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 10:02:33 2024 UTC