Link to home
Start Free TrialLog in
Avatar of qwertq
qwertq

asked on

Multi-dem array sort

Multi-demension arrays always get me... I need help sorting this array two ways.

Array
(
    [1] => Array
        (
            [timestamp] => 1153408578
        )
    [2] => Array
        (
            [timestamp] => 1153408589
        )
    [3] => Array
        (
            [timestamp] => 1153408592
        )
    [2.txt] => Array
        (
            [timestamp] => 1153408593
        )
    [3.txt] => Array
        (
            [timestamp] => 1153408593
        )
)

#1 : I would like to sort the array by the key, maintaining the inside array. I tried ksort, but it did not appear to work.

#2 : I would like to sort the array the array but the timestamp, maintaining the associations.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of snoyes_jw
snoyes_jw
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of qwertq
qwertq

ASKER

this array has been ksort($array) 'ed

notice how it is out of order (the keys). the 1 is at the bottom and the 1.txt is at the top... ?

Array
(
    [1.txt] => Array
        (
            [timestamp] => 1153408592
        )

    [2.txt] => Array
        (
            [timestamp] => 1153408593
        )

    [3.txt] => Array
        (
            [timestamp] => 1153408593
        )

    [a] => Array
        (
            [timestamp] => 1153408596
        )

    [a.jpg] => Array
        (
            [timestamp] => 1153414940
        )

    [b] => Array
        (
            [timestamp] => 1153408599
        )

    [b.jpg] => Array
        (
            [timestamp] => 1153417257
        )

    [c] => Array
        (
            [timestamp] => 1153408604
        )

    [c.jpg] => Array
        (
            [timestamp] => 1153417279
        )

    [1] => Array
        (
            [timestamp] => 1153408578
        )

    [2] => Array
        (
            [timestamp] => 1153408589
        )

    [3] => Array
        (
            [timestamp] => 1153408592
        )

)
that is normal ksort behaviour, 1.txt comes before 1

and 1. comes before 1.txt

no idea why, something do with how ksort works..
Avatar of qwertq

ASKER

why is 1 coming after a then?
why are we here?
is there a god?
why dont you ask the guy who wrote ksort.

it seems a string 'a' will come before a string '1'

but an integer 1 will come before a string 'a'

Avatar of qwertq

ASKER

can you suggest an atlerntaive to sort by key as all strings. i would like it to display the normal human way of alphabatizing
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial