欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

php从数组中随机获取值,拼接成新的随机字符串

程序员文章站 2022-07-14 19:49:04
...
//数组封装
$enStr = ['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','0','1','2','3','4','5','6','7','8','9'];

//打乱数组顺序
shuffle($enStr);

//获取新的数值,因为每次调用函数,数组都是重新排序过的,所以随机取值 array_slice($array,$offset,$length) 开始取值的第一个数 $offset 也可以是变动的
$newEnStr = array_slice($enStr,1,25);

//拼接随机字符串
echo implode('', $newEnStr);
die;