php 生成唯一订单
//生成唯一订单
function build_order_no(){
return date('ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
}
//获取唯一序列号
public static function generateNum() {
//strtoupper转换成全大写的
$charid = strtoupper(md5(uniqid(mt_rand(), true)));
$uuid = substr($charid, 0, 8).substr($charid, 8, 4).substr($charid,12, 4).substr($charid,16, 4).substr($charid,20,12);
return $uuid;
}
--------------------------------------------
<?php
$units = array();
for($i=0;$i<1000000;$i++){
$units[] = md5(uniqid(md5(microtime(true)),true));
}
$values = array_count_values($units);
$duplicates = [];
foreach($values as $k=>$v){
if($v>1){
$duplicates[$k]=$v;
}
}
//这种方法生成的唯一标识中没有重复。
echo '<pre>';
print_r($duplicates);
echo '</pre>';
?>
赞赏码
![](https://files.cnblogs.com/files/lxwphp/zhifubao2.bmp)
![](https://files.cnblogs.com/files/lxwphp/weixin.bmp)
非学,无以致疑;非问,无以广识