最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php获取指定数量随机字符串的方法
时间:2022-06-24 14:57:51 编辑:袖梨 来源:一聚教程网
本文实例讲述了php获取指定数量随机字符串的方法。分享给大家供大家参考,具体如下:
代码如下 | 复制代码 |
functiongetARandLetter($number= 1) { if($number== 0) returnFALSE;//去除0 $number=$number< 0 ? -$number:$number;//如果小于零取正值 $letterArr=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'); $returnStr='' for($i= 0;$i<$number;$i++) { $returnStr.=$letterArr[rand ( 0, 51 )]; } return$returnStr; } echogetARandLetter(8); |
运行结果:lUJfScvS