Current location: Hot Scripts Forums » Programming Languages » PHP » Sorting a massive multidimensional array


Sorting a massive multidimensional array

Reply
  #1 (permalink)  
Old 12-12-05, 02:38 PM
dave111 dave111 is offline
Wannabe Coder
 
Join Date: Jul 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
Sorting a massive multidimensional array

I have a big multidimensional array, and i found this on the forum to sort it:
Code:
$myRay = Array (
'0' => Array (
'id' => 1,
'name' => "name",
'login' => "123456789"
),
'1' => Array (
'id' => 2,
'name' => "foo",
'login' => "987654321"
),
'2' => Array (
'id' => 3,
'name' => "bar",
'login' => "423454321"
)
);



function namecmp( $row1,$row2 )
{
    return strcmp($row1['login'], $row2['login']) ;
   
}
uasort($myRay,'namecmp');
However after i sort it i then need to split it to different pages, so i have something like this:

Code:
foreach($myRay as $key =>$value) {
if (($mindisp <= $key) && ($key < $maxdisp)){
echo 'Value String' .$value;
}
}
And because it limits it using the $key it cancels out the sort that was orginally done. Is there a way to make the sort renumber the arrays? so that instead of after sort looking like this:
Code:
$myRay = Array (
'0' => Array (
'id' => 1,
'name' => "name",
'login' => "123456789"
),
'2' => Array (
'id' => 2,
'name' => "foo",
'login' => "487654321"
),
'1' => Array (
'id' => 3,
'name' => "bar",
'login' => "987654321"
)
);
It looks like this:

Code:
$myRay = Array (
'0' => Array (
'id' => 1,
'name' => "name",
'login' => "123456789"
),
'1' => Array (
'id' => 2,
'name' => "foo",
'login' => "487654321"
),
'2' => Array (
'id' => 3,
'name' => "bar",
'login' => "987654321"
)
);
Reply With Quote
  #2 (permalink)  
Old 12-12-05, 04:09 PM
dave111 dave111 is offline
Wannabe Coder
 
Join Date: Jul 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
Nevermind i figured it out.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multidimensional Array Sorting Kage PHP 6 12-12-05 04:19 PM
Multidimensional Array as Session Object emily13 ASP.NET 1 11-29-05 06:54 AM
PHP multi-dimensional array sorting issue aqw PHP 2 06-24-05 11:09 PM
Serializing a set of arrays dannyallen PHP 2 10-11-04 03:04 AM
linking to iframe not working :( j0d JavaScript 5 01-19-04 08:14 PM


All times are GMT -5. The time now is 06:23 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.