按照特定顺序排序
tp5查询数据不排序 会默认asc 升序排序 不能满足项目逻辑需求
1.首先引入Expression类
use think\db\Expression;
2.排序时准备工作
// 自定义排序
<?php
$ids="1,3,2,5,7,9";
$exp=new Expression("field(id,$ids)");
// 查询时
$res=Db::table('table')->whereIn('id',$ids)
->order($exp)
->select();
这样便可自定义排序
原文链接:https://blog.csdn.net/weixin_44944193/article/details/139474281