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();

你可能感兴趣的:(php相关)