-1

如何从 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从和中回显 2 个单词的选择性随机播放line2

我想要这样的东西

two这个词来自line1

dd这个词来自line2

输出two ddee three

4

1 回答 1

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];
于 2013-08-25T12:46:34.987 回答