【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
yii2 in 集合查询排序失效解决方法
$resData = (new \yii\db\Query())
->select('*')
->from('product')
->where(['id' => $productIdsArray])
->all();
//查出的结果是升序排列的要想实现指定数组内的排序顺序可以使用下面的方法
$productIds = implode(',' , $productIdsArray);
$orderBy = (new \yii\db\Query())
->select('*')
->from('product')
->where(['id' => $productIdsArray])
->orderBy([new \yii\db\Expression("FIELD (id, $productIds)")])
->all();
来源:oschina
链接:https://my.oschina.net/hongjiang/blog/3151124