Make any posible combination of one string with php
Posted
by Johan
on Stack Overflow
See other posts from Stack Overflow
or by Johan
Published on 2010-04-11T12:56:26Z
Indexed on
2010/04/11
13:03 UTC
Read the original article
Hit count: 175
I need an algorithm that return all possible combination of all characters in one string.
I've tried:
$langd = strlen($input);
for($i = 0;$i < $langd; $i++){
$tempStrang = NULL;
$tempStrang .= substr($input, $i, 1);
for($j = $i+1, $k=0; $k < $langd; $k++, $j++){
if($j > $langd) $j = 0;
$tempStrang .= substr($input, $j, 1);
}
$myarray[] = $tempStrang;
}
But that only returns the same amount combination as the length of the string.
Say the $input is = "hey", the result would be: hey, hye, eyh, ehy, yhe, yeh.
© Stack Overflow or respective owner