Complex array sorting

Complex array sorting

am 27.11.2007 17:49:34 von cronet

Hi,

i want to do some sortings to a complex array.
The array structure is at the end of this message



Now I want the result sorted in that way:
SingleRoom ($hotel[0][Rooms][0][max_persons]) - lowest rate ($hotel[0]
[Rooms][0][overall])

or

DoubleRoom - lowest/highest rate


I have no clue how to solve this problem...

can those arrays be sorted with usort??

Regards,
alexander





[0] => Array
(
[Hotel] => Array
(
[id] => 9609
[name] => This is a test
[zip] => 86154
[created] => 2007-11-21 01:04:18
[modified] => 2007-11-24 14:18:57
)

[HotelDescriptions] => Array
(
[0] => Array
(
[id] => 104691
[descriptiontype_id] => 6
[hotel_id] => 12345
[description_de] => Test_de
[description_en] => Test_en
[created] => 2007-11-25 14:27:34
[modified] => 2007-11-25 14:27:37
)

)

[Rooms] => Array
(
[0] => Array
(
[hotel_id] => 12345
[room_id] => 1234508
[available] => 5
[roomtype] => 22
[max_persons] => 2
[rate_id] => 78431
[overall] => 168
)

[1] => Array
(
[hotel_id] => 12345
[room_id] => 1234507
[available] => 5
[roomtype] => 22
[max_persons] => 1
[rate_id] => 78431
[overall] => 116
)

[2] => Array
(
[hotel_id] => 12345
[room_id] => 1234505
[available] => 5
[roomtype] => 14
[max_persons] => 1
[rate_id] => 78431
[overall] => 103
)

[3] => Array
(
[hotel_id] => 12345
[room_id] => 1234506
[available] => 5
[roomtype] => 14
[max_persons] => 2
[rate_id] => 78431
[overall] => 148
)
[show] => 1
)

)
[1] => Array
(
[Hotel] => Array
(
[id] => 9610
[...]

Re: Complex array sorting

am 27.11.2007 19:15:20 von Shelly

cronet wrote:
> Hi,
>
> i want to do some sortings to a complex array.
> The array structure is at the end of this message
>
>
>
> Now I want the result sorted in that way:
> SingleRoom ($hotel[0][Rooms][0][max_persons]) - lowest rate ($hotel[0]
> [Rooms][0][overall])

How did you fill the array? I assume it was from a database search. If so,
why not simply let SQL do the sorting for you.. All you need then would a
clause such as ORDER BY room_size, rate, max_people DESC.

Shelly

Re: Complex array sorting

am 27.11.2007 20:32:38 von cronet

On 27 Nov., 19:15, "Shelly" wrote:
> cronet wrote:
> > Hi,
>
> > i want to do some sortings to a complex array.
> > The array structure is at the end of this message
>
> > Now I want the result sorted in that way:
> > SingleRoom ($hotel[0][Rooms][0][max_persons]) - lowest rate ($hotel[0]
> > [Rooms][0][overall])
>
> How did you fill the array? I assume it was from a database search. If so,
> why not simply let SQL do the sorting for you.. All you need then would a
> clause such as ORDER BY room_size, rate, max_people DESC.
>
> Shelly

Thanks for reply.

Sorry. I didn't wrote that. It's both. Some data I get from a MySQL
Database, and especially the [Rooms] i get from a Webservice as XML
File, which I added in a foreach to every parent...
I can't tell the webservice in what sorting order they shall send me
the data...

Re: Complex array sorting

am 28.11.2007 03:34:50 von myhusky

yes, usort() should do the trick .
---
http://devoger.blogspot.com