Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Sorting Array

  1. #1
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts

    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

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Posts
    301
    Thanks
    7
    Thanked 2 Times in 2 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •