从给定字符串中选择随机字符的方法

kay*_*kay 10 php

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

ale*_*lex 27

$str = 'helloworld';

$randomChar = $str[rand(0, strlen($str)-1)];
Run Code Online (Sandbox Code Playgroud)

CodePad.


You*_*nse 7

$string = 'helloworld'; 
$pos = rand(0,(strlen($string)-1));
echo $pos."th char is: ". $string[$pos];
Run Code Online (Sandbox Code Playgroud)