php如何去除重复数组值
这篇文章主要介绍php如何去除重复数组值,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
我们提供的服务有:做网站、网站制作、微信公众号开发、网站优化、网站认证、从江ssl等。为近千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的从江网站制作公司
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如何去除重复数组值”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!
网页名称:php如何去除重复数组值
地址分享:http://pwwzsj.com/article/gjjeje.html