How to sort array with objects by object property in Yii 2?

If you want to sort your array with objects by specific property in Yii 2 then you can use beautiful method ArrayHelper::multisort (&$array, $key, $direction = SORT_ASC, $sortFlag = SORT_REGULAR)
Example (you have unsorted array ‘history’ with objects):

Array
(
    [0] => stdClass Object
        (
            [sent_date] => 2016-01-28 13:42:10
            [type] => sent
            [body] => Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for lorem ipsum
        )

    [1] => stdClass Object
        (
            [sent_date] => 2016-01-29 10:08:35
            [type] => sent
            [body] => Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for lorem ipsum
        )

    [2] => stdClass Object
        (
            [sent_date] => 2016-01-31 10:08:35
            [type] => sent
            [body] => Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for lorem ipsum
        )

    [3] => stdClass Object
        (
            [sent_date] => 2015-12-01 10:08:35
            [type] => sent
            [body] => Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for lorem ipsum
        )

)

Continue reading How to sort array with objects by object property in Yii 2?