How do I generate arrangements of n elements taken k in PHP?
Posted: Wed Dec 02, 2009 5:12 am
I have the following code:
My problem is that I have no idea how to generate those arrangements. I have tried with substr() but unsuccessfully.
Code: Select all
<?php
$string = 'abcdefghijklmnoprqstuvwxyz';
$arrangements = array();
$i = 0;
while ($i < strlen($string)) {
$arrangements[] = A($i, strlen($string));//arrangements of strlen($string) elements taken $i each
$i++;
}
?>
<pre><?php print_r($arrangements) ?></pre>