
Untitled
By: a guest on
Apr 29th, 2012 | syntax:
PHP | size: 0.55 KB | hits: 21 | expires: Never
<?php
set_time_limit(0);
function permute($str){
if(strlen($str)<2){
return array($str);
}
$permutations = array();
$tail = substr($str, 1);
foreach(permute($tail) AS $permutation){
$length = strlen($permutation);
for ($i=0; $i<=$length; $i++){
$permutations[] = substr($permutation, 0, $i) . $str[0] . substr($permutation, $i);
}
}
return $permutations;
}
$permute = array_unique(permute("אבג דהוז"));
foreach($permute AS $unq){
$a = substr($unq, 0, -4);
$b = substr($unq, -4, 4);
echo $a." ".$b."<br>";
}
?>