进入贴吧 按标题检索 按内容检索 按作者检索 网页搜索 音乐检索
贴吧列表 | 推荐贴吧 | 精华主题 | 最热主题 | 申请吧主 | 我要举报 | 用户登录 | 用户注册 | 忘记密码? RSS feed
首 页 > php吧 > php随机字符串生成的3种方法 人气指数:[ 734 ] 
本主题共有帖子数 0 篇,   [<<] [1] [>>]
1 php随机字符串生成的3种方法
方法一:

$str = abcdefg;
$length = strlen($str);
$shuffledStr = ;
while ($length > 0) {
  $index = mt_rand(0, $length - 1);
  $shuffledStr .= $str[$index];
  $str = substr($str, 0, $index) . substr($str, $index + 1);
  $length--;
}
echo $shuffledStr;

方法二:

$str = abcdefg;
$array = str_split($str);
shuffle($array);
$shuffledStr = implode(, $array);
echo $shuffledStr;

方法三:

$str = abcdefg;
$array = str_split($str);
$shuffledStr = ;
while (!empty($array)) {
  $index = array_rand($array);
  $shuffledStr .= $array[$index];
  unset($array[$index]);
}
echo $shuffledStr;
作者:175.166.56.*      2024/6/14 21:06:43     打印   回复

本主题共有帖子数 0 篇,   [<<] [1] [>>]
标  题: *
UBB:
UBB: 粗体 斜体 下划线 左对齐 居中 右对齐 插入外部网址 插入邮箱地址 插入外部图片 插入代码 引用内容 +增加编辑行 -减少编辑行 →加大编辑框宽度 ←缩小编辑框宽度
内  容: *
* 注:系统要求你是会员身份才能使用上传功能!
图  片: 教您外部贴图
验证码: * 看不清?点击更换验证码!
216.73.216.202  登录 | 注册 | 忘记密码
 
Powered by tb.wanliancm.com   PostBar v3.5 ACCESS
eXECUTION: 0.07813 second(s). Google SiteMap