Home > 类库下载 > PHP类库 > Get random names using time and mt_rand function

Get random names using time and mt_rand function

高洛峰
Release: 2016-10-09 13:11:31
Original
1405 people have browsed it

This knowledge will be used in file uploading and other occasions. I haven’t learned object-oriented yet, so now I present it to you in functional form

<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/9/19 0019
 * Time: 19:47
 */
function rdname(){
    $t = getdate();
    $year=$t[&#39;year&#39;];
    $month = $t[&#39;mon&#39;]<10? "0".$t[&#39;mon&#39;]:$t[&#39;mon&#39;];
    $day = $t[&#39;mday&#39;]>9?$t[&#39;mday&#39;]:"0".$t[&#39;mday&#39;];
    $hour= $t[&#39;hours&#39;]>9?$t[&#39;hours&#39;]:"0".$t[&#39;hours&#39;];
    $min = $t[&#39;minutes&#39;]>9?$t[&#39;minutes&#39;]:"0".$t[&#39;minutes&#39;];
    $sec = $t[&#39;seconds&#39;]>9?$t[&#39;seconds&#39;]:"0".$t[&#39;seconds&#39;];
    $randnum=mt_rand(1000,9999);//获取随机的4个数字
    $randname=$year.$month.$day.$hour.$min.$sec.$randnum;//把年月日时分和随机数拼接起来
   return $randname;//返回新的名字
}
$newname=rdname();//把返回的名字赋值给$newname
echo $newname; ?>
Copy after login

Effect display:

Get random names using time and mt_rand functionGet random names using time and mt_rand function

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template