gpt4 book ai didi

php - 一种从给定字符串中选择随机字符的方法

转载 作者:可可西里 更新时间:2023-10-31 22:53:13 25 4
gpt4 key购买 nike

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

最佳答案

$str = 'helloworld';

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

CodePad .

关于php - 一种从给定字符串中选择随机字符的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5311349/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com