Forum Moderators: coopster
<?
//Put your array here
$yourArr=array("[val1]","[val2]","[val3]");
$n=count($yourArr);
for ($i=0; $i <= $n; $i++) $pArr[$i]=$i; //The permutation array.
function PrintPerm()
{
global $yourArr,$pArr,$n;
for ($i=1; $i <= $n; $i++) echo $yourArr[$pArr[$i]-1];
echo "<br>";
return;
}
function swapThem($i,$j)
{
global $pArr;
$temp = $pArr[$i];
$pArr[$i] = $pArr[$j];
$pArr[$j] = $temp;
}
function NextPerm()
{
global $pArr,$n;
$k = $n-1;
while ($pArr[$k] > $pArr[$k+1]) $k--;
if ($k == 0) return(0);
else
{
$j = $n;
while ($pArr[$k] > $pArr[$j]) $j--;
swapThem($j,$k);
$r = $n;
$s = $k+1;
while ($r > $s)
{
swapThem($r,$s);
$r--;
$s++;
}
}
PrintPerm();
return(1);
}
//Print the array values
PrintPerm();
while (NextPerm()); //Permute and print
?>
$yourArr=array("[val1]","[val2]","[val3]");
$n=count($yourArr);
to:
$yourArr = count($name);
$n=count($yourArr);
there is no print out on the screen. I am sure the values are in $name but this won't pass on. Am I using the wrong syntax?