For part of the job, here's a routine I keep handy
function LexicographicPermutations($l)
{
$n = count($l);
if($n == 0 || $n == 1)
return array($l);
if($n == 2)
return array($l, array_reverse($l));
$table = array();
for($i = 0; $i < $n; ++$i)
{
$new = $l;
$li = $new[$i];
unset($new[$i]);
$new = LexicographicPermutations(array_values($new));
foreach($new as $k=>$v)
array_unshift($new[$k], $li);
$table[] = $new;
}
return call_user_func_array('array_merge', $table);
}
$array = str_split('rada');
print_r(array_map('join', LexicographicPermutations($array)));
It doesn't recognise duplicates, and works on arrays rather than strings (hence the splitting and joining) and of course doesn't do the different capitalisations, but of course its result can have those things done to it afterwards.