Sorting Array on PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Musti445
Forum Newbie
Posts: 1
Joined: Thu Aug 27, 2009 11:31 am

Sorting Array on PHP

Post by Musti445 »

Hello,

Im working on application and im pulling data and keeping them into Array. Here is the array :

Array ( [0] => Array ( [Picscore] => 4 [Picstotalvote] => 4 [Userid] => 165703106 [PicID] => 3155771420245492384 ) [1] => Array ( [Picscore] => 4 [Picstotalvote] => 4 [Userid] => 165703106 [PicID] => 3155771420245492385 ) [2] => Array ( [Picscore] => 7.3333333333333 [Picstotalvote] => 3 [Userid] => 165703106 [PicID] => 711689421146404998 ) [3] => Array ( [Picscore] => 9.5 [Picstotalvote] => 2 [Userid] => 165703106 [PicID] => 711689421146322449 ) [4] => Array ( [Picscore] => 6 [Picstotalvote] => 2 [Userid] => 165703106 [PicID] => 2609110194718361717 ) [5] => Array ( [Picscore] => 8 [Picstotalvote] => 2 [Userid] => 165703106 [PicID] => 711689421146274711 ) [6] => Array ( [Picscore] => [Picstotalvote] => 0 [Userid] => 165703106 [PicID] => 711689421146337639 ) [7] => Array ( [Picscore] => [Picstotalvote] => 0 [Userid] => 165703106 [PicID] => 711689421146219965 ) [8] => Array ( [Picscore] => 4 [Picstotalvote] => 4 [Userid] => 165703106 [PicID] => 3155771420245492384 ) )

Everything is good so far. but i would like to sort it by 'Picscore' . I tried sort() , asort() and arsort(); but non of them worked. What can i do?

Thanks
Musti
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Sorting Array on PHP

Post by requinix »

If you write a function that can sort two items (in the array) then you can use usort.
Post Reply