<?
function permutations( $set , $length )
{
$permutations = array();
foreach( $set as $option_number => $option )
{
if ( $length > 1 )
{
$sub_set = $set;
array_splice( $sub_set , $option_number , 1 );
$sub_permutations = permutations( $sub_set , $length - 1 );
foreach( $sub_permutations as $option_end )
{
$sub_option = $option_end;
array_unshift( $sub_option , $option );
$permutations[] = $sub_option;
} } else
$permutations[] = array( $option );
} return $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" );
?>