try using usort() instead of uksort() - (i haven't checked the manual but) I
believe uksort is for sorting based on the keys and not the values, which is
what you're trying to do

-----Original Message-----
From: Bloom, Chris [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 02, 2002 9:57 AM
Cc: Bloom, Chris
Subject: [PHP] Sorting Multi-Dimensional Arrays using uksort()

Hey folks: 

I have a function that returns an array. I'm assigning the returned array to
a variable inside another function: 
$dirs = getFileArray($parentDir,"title_2.txt"); 

If I use print_r() on the variable it writes out as expected: 
[0] => Array 
[folderName] => 97StudioPhotos 
[linkText] => Studio 3/27 - 3/30 (by Matt Myrdal/VE) 
[sortDate] => 03/31/02 


[1] => Array 
[folderName] => 98PromoPhotos 
[linkText] => Promo Photos BW (by Matt Myrdal - 3/24/02) 
[sortDate] => 03/24/02 


[2] => Array 
[folderName] => 99PhotoSet1 
[linkText] => Photo Set I (by Matt Myrdal - 3/12/02) 
[sortDate] => 03/12/02 



Now I want to sort this array using a custom defined sort method: 

function sortByDateDesc($a,$b) 
print "<hr>a = <br>"; 
print "<hr>"; 

print "<hr>b = <br>"; 
print "<hr>"; 

print $a." vs ".$b."<br>"; 

if ($a[sortDate] > $b[sortDate]){ 
print " ".$a[sortDate]." > ".$b[sortDate]."<br>"; 
return -1; 
} else if ($a[sortDate] < $b[sortDate]){ 
print " ".$a[sortDate]." < ".$b[sortDate]."<br>"; 
return 1; 
} else { 
print " ".$a[sortDate]." = ".$b[sortDate]."<br>"; 
return 0; 

As you can see, I've added a bunch of print() calls for testing. The trouble
is that none of the variables are being output into the print functions and
all of the print_r() calls just return "1". In the end, the array is not
being sorted at all. Why can't I access any of the array elements in this
function and why won't it sort correctly? 

I've tried accessing the elements everyway I can think of: 

Chris Bloom
PS: Attached is an example file
Web Infrastructure Analyst
Lifespan Corporate Services
167 Point Street #245
Providence, RI 02903

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to