在thinkphp中,distinct()方法用于去除重復(fù)的值,能夠返回唯一不同的值,distinct方法的參數(shù)是一個布爾值,語法為“$Model->distinct(布爾值參數(shù))->field('name')->select();”。
本文操作環(huán)境:Windows10系統(tǒng)、ThinkPHP5版、Dell G3電腦。
TP中distinct()的用處主要是去除重復(fù)的值
DISTINCT 方法用于返回唯一不同的值 。
$Model->distinct(true)->field('name')->select();
生成的SQL語句是:?
立即學(xué)習(xí)“PHP免費學(xué)習(xí)筆記(深入)”;
SELECT DISTINCT name FROM think_user
示例如下:
顯示的是這樣的
在加入distinct的話:
顯示結(jié)果為
下面為貼出來的代碼
$offernum = M('offer')->distinct(true)->where('order_id='.$order_id)->field('user_id,number')->select(); dump($offernum);
推薦學(xué)習(xí):《PHP視頻教程》
以上就是thinkphp中distinct的用法是什么的詳細內(nèi)容,更多請關(guān)注php中文網(wǎng)其它相關(guān)文章!
PHP怎么學(xué)習(xí)?PHP怎么入門?PHP在哪學(xué)?PHP怎么學(xué)才快?不用擔心,這里為大家提供了PHP速學(xué)教程(入門到精通),有需要的小伙伴保存下載就能學(xué)習(xí)啦!
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號