php - 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();
我们可以对这两个数组进行排序吗?
解决方案
推荐阅读
- c# - VS2019社区升级到专业版报错CS0579
- vulkan - vkQueuePresentKHR 上的 vkMapMemory 验证错误,但从未直接调用该函数
- php - 如何从 jquery 更新树枝变量?
- flutter - 使用提供者值颤振初始路由
- android - Android:导航组件 - 如何将工具栏菜单连接到片段?
- arm - 我的线程没有出现在 Keil uvision 的 RTOS 手表上
- c++ - 如何捕获 ssh_options_set 函数的异常
- vue.js - 关于 vue-rouer addRoutes 的问题
- windows - 为什么某些变量需要 %variable% 语法来访问其值,而其他变量不需要在窗口 cmd 中
- html - 无法在 optgroup 标签属性中正确添加 html img 或图标