Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-06-2010, 06:32 PM   PM User | #1
the-dream
Regular Coder

 
the-dream's Avatar
 
Join Date: Mar 2007
Location: Northamptonshire, UK
Posts: 477
Thanks: 8
Thanked 4 Times in 4 Posts
the-dream can only hope to improve
Sorting Array

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:
Code:
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
__________________
Branchr Advertising Network
the-dream is offline   Reply With Quote
Old 03-06-2010, 10:53 PM   PM User | #2
MattyUK
Regular Coder

 
Join Date: Jul 2002
Posts: 301
Thanks: 7
Thanked 2 Times in 2 Posts
MattyUK is on a distinguished road
I am not entirely sure but I think this may be what you need.
http://us.php.net/manual/en/function...-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.
MattyUK is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:34 PM.


Advertisement
Log in to turn off these ads.