0
Array
(
    [0] => Array
        (
            [sales] => 117513.00000000
            [month] => 1
            [month_name] => January
            [year] => 2018
        )

    [1] => Array
        (
            [purchases] => 136350.00000000
            [month] => 9
            [month_name] => September
            [year] => 2017
        )

    [2] => Array
        (
            [sales] => 23025.00000000
            [month] => 11
            [month_name] => November
            [year] => 2017
        )

    [3] => Array
        (
            [sales] => 6447.00000000
            [month] => 12
            [month_name] => December
            [year] => 2017
        )

)

Here I already sorted the array by year wise , but I need to sort by month descending .

Array
(

 [0] => Array
        (
            [sales] => 117513.00000000
            [month] => 1
            [month_name] => January
            [year] => 2018
        )

    [1] => Array
        (
            [purchases] => 6447.00000000
            [month] => 12
            [month_name] => December
            [year] => 2017
        )

    [2] => Array
        (
            [sales] => 23025.00000000
            [month] => 11
            [month_name] => November
            [year] => 2017
        )

    [3] => Array
        (
            [sales] => 136350.00000000
            [month] => 9
            [month_name] => September
            [year] => 2017
        )

)

How can I get the second format , which is sorted by month..

0

1 Answer 1

0

Use array_multisort function to do this.

<?php

// Obtain a list of columns
foreach ($data as $key => $row) {
  $month[$key]  = $row['month'];
}


array_multisort($month, SORT_DESC);
?>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.