Mine uses an incrementing binary number with the same number of digits as characters in the string. The 1s and 0s dictate the uppercase/lowercase combination. So without further adieu, here's the code...
Code: Select all
function AllCases($s) {
$s = strtolower($s);
$s2 = strtoupper($s);
$c = array();
$l = strlen($s);
for ($i = 0, $t = bindec(str_pad('', $l, '1')); $i <= $t; $i++){
$c[] = $s;
$x = str_pad(decbin($i), $l, '0', STR_PAD_LEFT);
for ($w = 0; $w < $l; $w++){
$c[$i][$w] = ($x[$w] === '1') ? $s2[$w] : $s[$w];
}
}
return $c;
}It would be faster if I could increment the binary number directly instead of converting it every time. Does anyone know if PHP can do that?