使用爆炸时,我不知道如何每两个字加下划线。
<?php
$original_sentence = "Rayane,Jack,John,Kriss,Bob,Steph";
$words = explode(",", $original_sentence);
shuffle($words);
echo implode(",",$words);
?>
我想在Jack的名字下划线,然后显示2个下一个名字,然后再次下划线。像这样:
Rayane,Jack,
John,Kriss,
Bob,Steph
答案 0 :(得分:0)
您可以使用array_chunk
<?php
$original_sentence = "Rayane,Jack,John,Kriss,Bob,Steph";
$explode_array = explode(',',$original_sentence);
//For randomizes the order of the elements in the array use shuffle
shuffle($explode_array);
$array = array_chunk($explode_array,2);
foreach($array as $value){
echo implode(',', $value) .'<br>';
}
?>