I try to get all combination upper and lower case characters of string. For example my string is abc
. I need to get result like this, all combinations for 3 characters of string: (2^0) x (2^1) x (2^2) = 8
:
abc
Abc
ABc
ABC
aBC
abC
AbC
aBc
My code is this but I have a problem, my code have duplicate cases and not return AbC
and aBc
:
<?php
function opposite_case($str)
{
if(ctype_upper($str))
{
return strtolower($str);
}
else
{
return strtoupper($str);
}
}
$str = "abc";
for($i = 0 ; $i < strlen($str) ; $i++)
{
for($j = 0 ; $j < strlen($str) ; $j++)
{
$str[$j] = opposite_case($str[$j]);
echo $str."<br>";
}
}
?>