首页 > 解决方案 > Yii 使用 Field 对 gridview 进行排序

问题描述

一次可以对 2 个数组进行排序,我们需要对数组 1 进行排序,然后我们需要对第二个进行排序

 $array_ids = [5,7,3,9,2,8,1] //simple array
    $array_id2 = [78999, 89855,,...]//second array

    $modelsObj = Model::find()
            ->where(['id' => $array_ids]) // find only needed id's
            ->limit(5) //add limit if you need
            ->orderBy([new \yii\db\Expression('FIELD(id, '. implode(',', $array_ids) . ')')]) // sorting them as in array
            ->all();

我们可以对这两个数组进行排序吗?

标签: phpdatabaseyii2

解决方案


推荐阅读