如何洗牌& Echo 2来自2行的随机单词?

时间:2013-08-25 12:43:31

标签: php arrays string explode shuffle

如何改变& 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原始字符串

来自line1line2

的2个字的回声选择性随机播放

我想要这样的东西

two这个词来自line1

dd这个词来自line2

输出two ddee three

1 个答案:

答案 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];