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: Ksort problem

  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    96
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Exclamation Ksort problem

    Hi,

    I have the following array - how do I sort it so that it's in numerical key order? I tried ksort() but had no joy

    [0]=>
    array(4) {
    ["field_display_name"]=>
    string(5) "title"

    }
    [7]=>
    array(4) {
    ["field_display_name"]=>
    string(13) "object_number"

    }
    [1]=>
    array(4) {
    ["field_display_name"]=>
    string(11) "description"
    }
    [2]=>
    array(4) {
    ["field_display_name"]=>
    string(19) "content.description"

    }
    [6]=>
    array(4) {
    ["field_display_name"]=>
    string(15) "content.subject"

    }
    [5]=>
    array(4) {
    ["field_display_name"]=>
    string(7) "creator"

    }
    [4]=>
    array(4) {
    ["field_display_name"]=>
    string(16) "production.place"

    }
    [3]=>
    array(4) {
    ["field_display_name"]=>
    string(21) "production.date.start"

    }
    }

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    ksort() worked fine for me....

    Original array
    Array
    (
    [0] => Array
    (
    [field_display_name] => title
    )

    [7] => Array
    (
    [field_display_name] => object_number
    )

    [1] => Array
    (
    [field_display_name] => description
    )

    [2] => Array
    (
    [field_display_name] => content.description
    )

    [6] => Array
    (
    [field_display_name] => content.subject
    )

    [5] => Array
    (
    [field_display_name] => creator
    )

    [4] => Array
    (
    [field_display_name] => production.place
    )

    [3] => Array
    (
    [field_display_name] => production.date.start
    )

    )

    Sorted array

    Array
    (
    [0] => Array
    (
    [field_display_name] => title
    )

    [1] => Array
    (
    [field_display_name] => description
    )

    [2] => Array
    (
    [field_display_name] => content.description
    )

    [3] => Array
    (
    [field_display_name] => production.date.start
    )

    [4] => Array
    (
    [field_display_name] => production.place
    )

    [5] => Array
    (
    [field_display_name] => creator
    )

    [6] => Array
    (
    [field_display_name] => content.subject
    )

    [7] => Array
    (
    [field_display_name] => object_number
    )

    )
    Maybe you could show the code you're using?


  •  

    Posting Permissions

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