|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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..
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 06:00:01 2025 UTC |
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"; ?>