使用PHP随机播放多个字符串值 [英] shuffle multiple string values using PHP

查看:84
本文介绍了使用PHP随机播放多个字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hiii大家

每个问题我有4个选项.每个字符串都带有冗长的句子.我的变量将像option1,option2,option3,option4.像随机函数一样随机播放.我以多种方式搜索了用于数字的Random()函数,然后看到str_shuffle()只能将一个字符串随机播放,而两个则以字符串折叠的方式进行随机播放.我只想重新排列字符串的顺序.PHP可以做到这一点.因此,请为我提供解决方案.谢谢.

I have 4 options for each question.Each string Is carrying Lengthy sentences.My variables will be like option1,option2,option3,option4.I want to shuffle this variable order like 3,2,1,4 or similarly it will shuffle like random function.I searched in many way Random() function used for numbers and I saw str_shuffle() it will shuffle only one string that two with string collapse.I want just to rearrange strings order .Is this possible with PHP.If its so please help me with Solution.Thanks in advance.

推荐答案

最好使用数组来实现.

$options = array(
  'Option One',
  'Option Two',
  'Option Three',
  'Option Four'
); 
//Shuffle the array
shuffle($options);

您可以访问这样的选项(顺序是随机的);

You can access the options like this (The order will be random);

$options[0];
$options[1];
$options[2];
$options[3];

这篇关于使用PHP随机播放多个字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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