1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| <?php
set_time_limit(5) ;
header('Content-Type: text/plain') ;
$tokens = array('[pomme]', '[fraise]', '[banane]') ;
$length = 2 ;
$base = count($tokens) ;
$possibilities = pow($base, $length) ;
$result = array( ) ;
for ( $i = 0 ; $i < $possibilities ; $i++ ) {
$mask = str_pad(base_convert($i, 10, $base), $length, '0', STR_PAD_LEFT) ;
$buffer = '' ;
for ( $j = 0 ; $j < $length ; $j++ ) {
$buffer .= $tokens[(int)$mask[$j]] ;
}
$result[ ] = $buffer ;
}
echo $possibilities, " résultats\r\n\r\n" ;
print_r($result) ;
?> |
Partager