php.net |  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
Votes:2
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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
7 + 4 = ?
Subscribe to this entry?

 
 [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..

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-22 03:58 UTC] mfischer@php.net
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] 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:40 UTC] 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-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: Wed Jun 19 09:01:29 2024 UTC