Q:

Sort mixed models with one dataprovider using ArrayDataProvider

I used ArrayDataProvider to mix models and then merged them into one data-provider.  I used the data-provider in grid-view and everything is works fine. 
But I need to order the grid-view by one column I tried a lot of solutions but none of them are worked. 
This my model code (order by item_order )
public function getAllSelectedItemsInTheUnit($unitId, $grid = false)
    {
        $finalList = array();
        $storiesList = array();
        $activityList = array();
        $breakList = array();
        $stories = UnitStories::find()->joinWith(['story'])->where("unit_id=$unitId")->all();
        if (count($stories) > 0) {
            foreach ($stories as $item) {
                $storiesList[] = [
                    'key' => self::TYPE_STORY .  $item->id,
                    'id' => $item->id,
                    'title' => $item->story->title,
                    'type' => self::TYPE_STORY,
                    'item_order' => $item->unit_order,
                ];
            }
        }

        $activities = UnitActivities::find()->joinWith(['activity'])->where("unit_id=$unitId")->all();
        if (count($activities) > 0) {
            foreach ($activities as $item) {
                $activityList[] = [
                    'key' => self::TYPE_ACTIVITY .  $item->id,
                    'id' => $item->id,
                    'title' => $item->activity->title,
                    'type' => self::TYPE_ACTIVITY,
                    'item_order' => $item->activity_order,
                ];
            }
        }

        $breaks = UnitBreaks::find()->where("unit_id=$unitId")->all();
        if (count($breaks) > 0) {
            foreach ($breaks as $item) {
                $breakList[] = [
                    'key' => self::TYPE_BREAK .  $item->id,
                    'id' => $item->id,
                    'title' => $item->title,
                    'type' => self::TYPE_BREAK,
                    'item_order' => $item->unit_order,
                ];
            }
        }
         $finalList = array_merge($storiesList, $activityList, $breakList);
         $dataProvider = new ArrayDataProvider([
                'allModels' => $finalList, 'key' => 'key',
                'sort' => [
                    'attributes' => ['item_order'],
                ],

            ]);

            return $dataProvider;

    }

Any solution will be very good even sort array by pure PHP I guess will fix the problem . 

A:

You can use usort()
usort($finalList, function ($a, $b) {
    return $a['item_order'] < $b['item_order'];
});

Add your condition in callback >, <, <= etc

