Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何洗牌&;从两行中回送两个随机单词?_Php_Arrays_String_Explode_Shuffle - Fatal编程技术网

Php 如何洗牌&;从两行中回送两个随机单词?

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

如何洗牌和回音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

只需将这两行分解成单独的数组,然后将它们洗牌。大概是这样的:

$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]