thinkphp where in order 按照順序in的迴圈排序

admin⁠發表於2020-12-14

主題列表:juejin, github, smartblue, cyanosis, channing-cyan, fancy

貢獻主題:https://github.com/xitu/juejin-markdown-themes

theme: juejin
highlight: juejin

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

    }

}



相關文章