Help in array sorting problem.

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
lovelyThumbsUp
Forum Newbie
Posts: 2
Joined: Tue Oct 07, 2008 5:05 pm

Help in array sorting problem.

Post by lovelyThumbsUp »

:?: :?: :?: :?:
First of all, thanks for everyone willing to helps me out~!

OK here is my question:

I got three arrays (listed below), I am tried to find a way out to sort these arrays by "clipa", "clipb", "clipc", "clipd", which means, if I choose "clipa", all the arrays with "clipa =>1" will go on top of the array( some resort here) and print out in priority.


For example:

choosed: clipa

out print:

1) id = 0060
2) id = 0062
3) id = 0061


choosed: clipc

out print:


1) id = 0060
2) id = 0061
3) id = 0062


-----------------------------------------------------------------
Array 1
(
[id] => 0060
[content] => Array
(
[clipa] => 1
[clipb] =>
[clipc] => 1
)

)


Array 2
(
[id] => 0061
[content] => Array
(
[clipa] =>
[clipb] => 1
[clipc] => 1
)

)

Array 3
(
[id] => 0062
[content] => Array
(
[clipa] => 1
[clipb] =>
[clipc] =>
)

)

---------------------------------------------------------------

Is there anyone have any idea how to do this? Or which way should I looking into?

Thanks Thanks Thanks

L
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Help in array sorting problem.

Post by VladSun »

Write your own compare function and use
http://bg2.php.net/manual/en/function.usort.php
There are 10 types of people in this world, those who understand binary and those who don't
lovelyThumbsUp
Forum Newbie
Posts: 2
Joined: Tue Oct 07, 2008 5:05 pm

Re: Help in array sorting problem.

Post by lovelyThumbsUp »

VladSun wrote:Write your own compare function and use
http://bg2.php.net/manual/en/function.usort.php
Thanks VladSun, I finally got it.
Post Reply