如何改变& Echo 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
原始字符串
来自line1
和line2
我想要这样的东西
two
这个词来自line1
dd
这个词来自line2
输出two dd
或ee three
答案 0 :(得分:1)
将这两行分解为单独的数组,然后将它们随机播放。像这样:
$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];