distinct方法怎么在Thinkphp 中使用

distinct方法怎么在Thinkphp 中使用

本篇文章为大家展示了distinct方法怎么在Thinkphp 中使用,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

TP中distinct()的用处主要是去除重复的值

在Thinkphp手册中也详细说明了(链接:http://document.thinkphp.cn/manual_3_2.html#distinct)

下面是我的个人例子:

distinct方法怎么在Thinkphp 中使用

显示的是这样的

distinct方法怎么在Thinkphp 中使用

在加入distinct的话:

distinct方法怎么在Thinkphp 中使用

显示结果为

distinct方法怎么在Thinkphp 中使用

下面为贴出来的代码

$offernum = M('offer')->distinct(true)->where('order_id='.$order_id)->field('user_id,number')->select();
dump($offernum);

上述内容就是distinct方法怎么在Thinkphp 中使用,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注行业资讯频道。