thinkphp where in order 按照顺序in的循环排序

336 阅读1分钟
<?php
/**
 * Created by.
 * User: Jim
 * Date: 2020/11/16
 * Time: 9:11
 */

namespace app\index\controller;


use think\Controller;
use think\Db;
use think\db\Expression;

class Test extends Controller
{
    public function index()
    {

        $ids = implode(',',[1,4,844,6,900,10]);
        $exp = new Expression('field(id,'.$ids.')');
        $datas = Db::name('goods')
            ->whereIn('id',$ids)
            ->field('id,rank')
            ->order($exp)
            ->select();

        dump($datas);

    }

}