User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Reply
Thread Tools Display Modes
Unread 18 Jan 2005, 11:57   #1
CaShY
Registered User
 
CaShY's Avatar
 
Join Date: Jul 2002
Location: uk
Posts: 50
CaShY is an unknown quantity at this point
PHP sorting arrays by a Key

Hi anyone know how to sort a multidimensional array by a key in php?


the data goes

Array [0] ( [id] => 1 [link] => link [weight] => 10 )
Array [1] ( [id] => 2 [link] => link [weight] => 1 )
Array [2] ( [id] => 3 [link] => link [weight] => 8 )
Array [3] ( [id] => 4 [link] => link [weight] => 10 )

I want to sort the array we shall call $links

by weight decending.

Looked everywere and i can't work it out any help out be great.
__________________
CaShY
CaShY is offline   Reply With Quote
Unread 19 Jan 2005, 01:53   #2
Add
Registered User
 
Join Date: Feb 2001
Posts: 442
Add will become famous soon enoughAdd will become famous soon enough
Re: PHP sorting arrays by a Key

Code:
foreach ($link as $val) {
     $sortarray[] = $val['weight'];
     $sortarray = array_reverse($sortarray, true);
}
array_multisort($sortarray,$link);
not tested...
__________________
Trust in my Instinct
Add is offline   Reply With Quote
Reply



Forum Jump


All times are GMT +1. The time now is 04:13.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018