Source Browser from MakeDataMakeSense.com

<?

    
function permutations$set $length )
    {
    
        
$permutations = array();
        
        foreach( 
$set as $option_number => $option )
        {
        
            if ( 
$length )
            {
            
                
$sub_set $set;
                
array_splice$sub_set $option_number );

                
$sub_permutations permutations$sub_set $length );

                foreach( 
$sub_permutations as $option_end )
                {

                    
$sub_option $option_end;
                    
array_unshift$sub_option $option );
                    
                    
$permutations[] = $sub_option;

                } 
// foreach

            
// if
            
else
                
$permutations[] = array( $option );
        
        } 
// foreach

        
return $permutations;
    
    } 
// permutations

    
$set = array( 'A' 'B' 'C' 'D' 'E' );
    
$length 3;

    
$permutations permutations$set $length );

    
header'Content-type: text/plain' );

    foreach( 
$permutations as $number => $permutation )
        echo( 
implode' ' $permutation ) . "n" );

?>