从给定字符串中选择随机字符的方法 [英] a method of selecting random characters from given string

查看:202
本文介绍了从给定字符串中选择随机字符的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以通过使用PHP从给定字符串中提取随机字符的位置和值的解决方案来帮助我.例如,我有一个字符串变量$ string ='helloworld';并希望从$ string中随机选择一个字符并回显该字符及其位置.

Can anyone help me with a solution that pulls the position and value of a random character from a given string using PHP. For example I have a a string variable $string = 'helloworld'; and would like to randomly select a character from $string and echo the character and its position.

推荐答案

$str = 'helloworld';

$randomChar = $str[rand(0, strlen($str)-1)];

CodePad .

这篇关于从给定字符串中选择随机字符的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆