All you need is
$str = "abab cdcd efef";
$list = array_map(function ($v) {
$v = str_split($v);
shuffle($v);
return implode(current(array_chunk($v, 2)));
}, explode(" ", $str));
echo "<pre>";
print_r($list);
Array
(
[0] => ab
[1] => cd
[2] => ef
)
1
solved How to randomly select characters from string using PHP? [closed]