...

View Full Version : Sorting Array



the-dream
03-06-2010, 07:32 PM
Hey Guys...

I know there are various functions for sorting arrays, but can't for the life of me figure out which one to use in this situation. I have the following array and I'm trying to keep it in the same format it is but sort each part by the [when] key.

If anyone can think of a way to do this, let me know.

Array:


Array
(
[1] => Array
(
[type] => post
[title] => As The Deals Roll In, So Does Some Revenue For Foursquare
[when] => 1266014658
[url] => http://christian.hivescribe.com/19/as-the-deals-roll-in,-so-does-some-revenue-for-foursquare/
)

[2] => Array
(
[type] => post
[title] => What the iPad means for portable computing.
[when] => 1265540236
[url] => http://christian.hivescribe.com/18/what-the-ipad-means-for-portable-computing/
)

[3] => Array
(
[type] => comment
[comment] => ROFL!!!
[commentername] =>
[commenteremail] =>
[post] => 19
[when] => 1266774692
[commentid] => 5
)

[4] => Array
(
[type] => comment
[comment] => LOL!
[commentername] =>
[commenteremail] =>
[post] => 19
[when] => 1266774668
[commentid] => 4
)

[5] => Array
(
[type] => comment
[comment] => Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
[commentername] =>
[commenteremail] =>
[post] => 19
[when] => 1266773960
[commentid] => 3
)

[6] => Array
(
[type] => comment
[comment] => Totally agree, and 4sq is kinda awesome... Has to be said.
[commentername] =>
[commenteremail] =>
[post] => 19
[when] => 1266773732
[commentid] => 2
)

[7] => Array
(
[type] => comment
[comment] => r
[commentername] =>
[commenteremail] =>
[post] => 19
[when] => 1266773242
[commentid] => 1
)

)


Thanks,
~ Christian

MattyUK
03-06-2010, 11:53 PM
I am not entirely sure but I think this may be what you need.
http://us.php.net/manual/en/function.array-multisort.php

There is also usort which allows you to create your own callback function.

Until I sit and play with them and your array I'm not sure if they will fit the bill.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum