我想以这种格式为每个客户创建一个唯一的用户ID。
XXXX-NNNN,其中X是字母表,N是数字。并且不应重复使用字母和数字。
发布于 2018-08-21 13:16:39
如果你想得到每个id创建strrev();
的时间,substr($string, 0, 10);
获得整数,你将得到一个unix时间戳,然后转换为你喜欢的任何时间格式。但如果你想要真正准确的唯一ID生成我建议你用@shivam
function bobby_tables()
{
$uni=uniqid(); //returns a unique string based on time
$newuserid=time(); //returns a UNXI time stamp
$uni=str_split($uni); //splits string in to an array
//data set to convert numbers to alphabets
$set= array('0'=>'A' ,'1' =>'B' ,'2'=>'C' ,'3'=>'D' ,'4'=>'E' ,'5'=>'F' ,'6'=>'G' ,'7'=>'H' ,'8'=>'I' ,'9'=>'J');
$i=0; //to increment array value in loop
//first loop converting a set of numbers to alphabets
foreach ( $uni as $key1 => $value1)
{
foreach ( $set as $key2 =>$value2)
{
if ($value1==$key2)
{
$newid[$i]=$value2;
}
}
$i++; //incremental
}
//second loop changing array to string
foreach ($newid as $key => $value)
{
$newuserid.= $value;
}
//reversing the string not really needed
$newuserid=strrev($newuserid);
return $newuserid; //return the end result
}
echo bobby_tables();
https://stackoverflow.com/questions/-100002320
复制相似问题