[Solved] How to randomly select characters from string using PHP? [closed]


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);

Output

Array
(
    [0] => ab
    [1] => cd
    [2] => ef
)

Simple Online Demo

1

solved How to randomly select characters from string using PHP? [closed]