I have a function that take a one dimensional array and returns all the possible permutations of the elements within the array;
function array_2D_permute($items, $perms = array()) {
static $permuted_array = array();
    if (empty($items)) {
        $permuted_array[]=$perms;
        #print_r($new);
        #print join(' ', $perms) . "\n";
    }  else {
        for ($i = count($items) - 1; $i >= 0; --$i) {
             $newitems = $items;
             $newperms = $perms;
             list($foo) = array_splice($newitems, $i, 1);
             array_unshift($newperms, $foo);
             array_2D_permute($newitems, $newperms);
         }
         return $permuted_array;
    }
}
$arr1=array("Architecture","Mexico","Periodicals");
$result1=array_2D_permute($arr1);
print_r($result1);
$arr2=array("Apple","Boat","Cat");
$result2=array_2D_permute($arr2);
print_r($result2);
The first time the function is called, it works as expected, however the second time it is called, it also includes elements from the first array. I can't figure out why this is.
Appreciate the help.
 
     
     
    