0

I was searching longer now and can't find some suitable like I guess.

I am sure the question must have an answere somewere here but I really can't find it :(

I have this none associative array and I want to sort it by the given timestamp

[data] => Array
    (
        [0] => Array
            (
                [0] => 1415228400000 //sort by this value
                [1] => 9826.5
            )

        [1] => Array
            (
                [0] => 1415401200000
                [1] => 29197.95
            )

        [2] => Array
            (
                [0] => 1417561200000
                [1] => 3916.35
            )

        [3] => Array
            (
                [0] => 1415142000000
                [1] => 22120
            )

        [4] => Array
            (
                [0] => 1414796400000
                [1] => 28345.35
            )

        [5] => Array
            (
                [0] => 1420412400000
                [1] => 858
            )

        [6] => Array
            (
                [0] => 1423004400000
                [1] => 132
            )

        [7] => Array
            (
                [0] => 1423522800000
                [1] => 0
            )

        [8] => Array
            (
                [0] => 1424214000000
                [1] => 231
            )

        [9] => Array
            (
                [0] => 1425510000000
                [1] => 123.45
            )

        [10] => Array
            (
                [0] => 1425596400000
                [1] => 2223.45
            )

    )

The thing is, I have to sort it in the third dimension, how can I do this?

Dwza
  • 6,494
  • 6
  • 41
  • 73
  • `usort()` will get it done. – Jason McCreary Mar 12 '15 at 15:13
  • @Rizier123 reading the Headline of the post would show you that your "Googlesearch" is absolutely failed! This sample also uses assoc array and I don't have a assoc array! – Dwza Mar 12 '15 at 15:14
  • And as I knew from beginning... it gets marked as duplicate and downvotet. Also the duplicatemark isn't that what i am looking for... great! – Dwza Mar 12 '15 at 15:16
  • @JasonMcCreary how can usort help me if its for assoc arrays ? – Dwza Mar 12 '15 at 15:17
  • 1
    `usort()` does not require an associative array. Take a look at the first answer of the duplicate questions. if you change `['order']` to `[0]`, you'll be 99% there. – Jason McCreary Mar 12 '15 at 15:20
  • 1
    @Dwza It's clearly a duplicated question and your answer is in the post indicated by Rizier123 – Cosmin Mar 12 '15 at 15:20
  • I like array_multisort way better, just supply ($sort_data, SORT_DESC, $data), you'll get your timestamp sorting. The array can or not be multi-dimentional it'll work well. There are other functions but you need to glue these pieces together. In addition, in SORT_DESC you can change your order. – unixmiah Mar 12 '15 at 15:23
  • i really tried several way, also this.. and I don't get it in order.... anyways... guess i will stay alone with this problem.... – Dwza Mar 12 '15 at 15:30
  • @unixmiah my arraysorting is on third dimension. Is this still possible – Dwza Mar 12 '15 at 15:35
  • @Cosmin eather im blind or the third dimension sorting answere is hiding from me! – Dwza Mar 12 '15 at 15:37
  • @Dwza yes you can, you can sort multidimensional/to the 3rd dimension or a nested array. You can even specify multiple column search with the function: array_multisort($column3, SORT_ASC, $column1, SORT_ASC, $column2, SORT_ASC, $arr); – unixmiah Mar 12 '15 at 15:46
  • @Dwza If I have an array $a[1][2][3][4] = 'test' it is on 4-th dim, but if I make $b = $a[1][2], then $b becomes a 2 dim just like if u do a damn $data = $your_array['data'] so $data becomes a 2 dim array instead of 3... – Cosmin Mar 13 '15 at 10:09
  • @Cosmin thx, i all ready solved my problem – Dwza Mar 13 '15 at 10:43

0 Answers0