- str_split: documentation ( source)
<?php
function createCombinations($input_str, $length) {
$input = str_split($input_str);
foreach($input as $c) {
if($length == 1) {
yield $c;
return;
}
else {
foreach(createCombinations($input_str, $length -1) as $s) {
yield $c + $s;
return;
}
}
}
}
$texte = "abcdefghijklmnopqrstuvwxyz0123456789";
foreach(createCombinations($texte, 4) as $result) {
echo $result;
}