php中如何使用rand()函数-创新互联
这篇文章主要介绍了php中如何使用rand()函数,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
成都创新互联主营贡山网站建设的网络公司,主营网站建设方案,成都APP应用开发,贡山h5微信小程序定制开发搭建,贡山网站营销推广欢迎贡山等地区企业咨询@session_start(); $currentTime = time(); $changeTime = 10; $rand = ''; if(isset($_SESSION['time'])) { if(($currentTime - $_SESSION['time']) >= $changeTime) { $_SESSION['time'] = $currentTime; $rand = (0, 9999); $_SESSION['rand'] = $rand; }else{ $rand = $_SESSION['rand']; } }else{ $_SESSION['time'] = $currentTime; $rand = (0, 9999); $_SESSION['rand'] = $rand; } = $changeTime) { switch ($_i){ case '0': $_SESSION['rand'][$_i] = mt_rand(100,200); $rand = $_SESSION['rand'][$_i]; break; case '1': $_SESSION['rand'][$_i] = mt_rand(200,300); $rand = $_SESSION['rand'][$_i]; break; case '2': $_SESSION['rand'][$_i] = mt_rand(300,400); $rand = $_SESSION['rand'][$_i]; break; } $_SESSION['time'][$_i] = $currentTime; }else{ switch ($_i){ case '0': $rand = $_SESSION['rand'][$_i]; break; case '1': $rand = $_SESSION['rand'][$_i]; break; case '2': $rand = $_SESSION['rand'][$_i]; break; } } }else{ if(!isset($_SESSION['time'])){ $_SESSION['time'] = array(); } switch ($_i){ case '0': $_SESSION['rand'][$_i] = mt_rand(100,200); $rand = $_SESSION['rand'][$_i]; break; case '1': $_SESSION['rand'][$_i] = mt_rand(200,300); $rand = $_SESSION['rand'][$_i]; break; case '2': $_SESSION['rand'][$_i] = mt_rand(300,400); $rand = $_SESSION['rand'][$_i]; break; } $_SESSION['time'][$_i] = $currentTime; } return $rand; } ?>| | |
感谢你能够认真阅读完这篇文章,希望小编分享的“php中如何使用rand()函数”这篇文章对大家有帮助,同时也希望大家多多支持创新互联,关注创新互联行业资讯频道,更多相关知识等着你来学习!
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网页标题:php中如何使用rand()函数-创新互联
分享路径:http://azwzsj.com/article/phdcc.html