Php 如何洗牌&;从两行中回送两个随机单词?
如何洗牌和回音2行中的2个随机单词 示例我的代码Php 如何洗牌&;从两行中回送两个随机单词?,php,arrays,string,explode,shuffle,Php,Arrays,String,Explode,Shuffle,如何洗牌和回音2行中的2个随机单词 示例我的代码 $lines1 = "one, two, three, four, five"; $lines2 = "aa, bb, cc, dd, ee"; $array=explode(",",$lines1, $lines2); shuffle($array); $newstring = implode($array,""); echo substr($newstring, 0, 1); $lines1$lines2原始字符串 从line
$lines1 = "one, two, three, four, five";
$lines2 = "aa, bb, cc, dd, ee";
$array=explode(",",$lines1, $lines2);
shuffle($array);
$newstring = implode($array,"");
echo substr($newstring, 0, 1);
$lines1
$lines2
原始字符串
从line1
和line2
我想要这样的东西
two
这个词来自line1
dd
这个词来自line2
输出
two-dd
或ee-three
只需将这两行分解成单独的数组,然后将它们洗牌。大概是这样的:
$lines1 = "one, two, three, four, five";
$lines2 = "aa, bb, cc, dd, ee";
$array1 = explode(",", $lines1);
shuffle($array1);
$array2 = explode(",", $lines2);
shuffle($array2);
echo $array1[0] ." ". $array2[0];
现在,我添加额外的代码
$myarray=explode(“,”,$array1[0]”,“,”$array2[0])代码>shuffle($myarray)代码>echo$myarray[0]。“”$myarray[1]代码>