您好,登錄后才能下訂單哦!
這篇文章主要介紹php如何去除重復數組值,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
php去除重復數組值的方法:首先打開相應的PHP代碼文件;然后通過“array_unique($ordernum);”去掉重復的字符串;最后輸出去重后的數組即可。
php去除數組中重復值,并返回結果!
$data = db('order')->field('ordernum')->where(array('user_id' => $user_id))->select();
查詢的數組格式
array(16) { [0] => array(1) { ["ordernum"] => string(18) "190415165656156213" } [1] => array(1) { ["ordernum"] => string(18) "190415165656156213" } [2] => array(1) { ["ordernum"] => string(18) "190415165656156213" } [3] => array(1) { ["ordernum"] => string(18) "190415170056183687" } [4] => array(1) { ["ordernum"] => string(18) "190415170056183687" } [5] => array(1) { ["ordernum"] => string(18) "190415170056183687" } [6] => array(1) { ["ordernum"] => string(18) "190415170345120966" } [7] => array(1) { ["ordernum"] => string(18) "190415170345120966" } [8] => array(1) { ["ordernum"] => string(18) "190415170345120966" } [9] => array(1) { ["ordernum"] => string(18) "190416174929158053" } [10] => array(1) { ["ordernum"] => string(18) "190416174929158053" } [11] => array(1) { ["ordernum"] => string(18) "190416194457158437" } [12] => array(1) { ["ordernum"] => string(18) "190416194457158437" } [13] => array(1) { ["ordernum"] => string(18) "190416195027154990" } [14] => array(1) { ["ordernum"] => string(18) "190416195027154990" } [15] => array(1) { ["ordernum"] => string(18) "190417124518178758" } } foreach ($data as $k => $v) { $ordernum[] = $v['ordernum']; }
ordernum數組格式
array(16) { [0] => string(18) "190415165656156213" [1] => string(18) "190415165656156213" [2] => string(18) "190415165656156213" [3] => string(18) "190415170056183687" [4] => string(18) "190415170056183687" [5] => string(18) "190415170056183687" [6] => string(18) "190415170345120966" [7] => string(18) "190415170345120966" [8] => string(18) "190415170345120966" [9] => string(18) "190416174929158053" [10] => string(18) "190416174929158053" [11] => string(18) "190416194457158437" [12] => string(18) "190416194457158437" [13] => string(18) "190416195027154990" [14] => string(18) "190416195027154990" [15] => string(18) "190417124518178758" } $ordernum = array_unique($ordernum); //去掉重復的字符串
去重后ordernum 數組格式
array(7) { [0] => string(18) "190415165656156213" [3] => string(18) "190415170056183687" [6] => string(18) "190415170345120966" [9] => string(18) "190416174929158053" [11] => string(18) "190416194457158437" [13] => string(18) "190416195027154990" [15] => string(18) "190417124518178758" } foreach ($ordernum as $k => $v) { $new_ordernum[] = $v; //拆分后的重組 }
產生的新數組格式
array(7) { [0] => string(18) "190415165656156213" [1] => string(18) "190415170056183687" [2] => string(18) "190415170345120966" [3] => string(18) "190416174929158053" [4] => string(18) "190416194457158437" [5] => string(18) "190416195027154990" [6] => string(18) "190417124518178758" }
以上是“php如何去除重復數組值”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。