How to create and write to text file a list of three-letter all combinations in PHP

1 Answer

0 votes
three_letters_combination();    
     
function three_letters_combination()
{
    $s = "abcdefghijklmnopqrstuvwxyz";
    
    $f = fopen("d:/three_letters_combination.txt", "a") or die("Error open file!");
  
    $s_size = strlen($s);
    for ($i = 0; $i < $s_size; $i++)
    {
        for ($j = 0; $j < $s_size; $j++)
        {
            for ($k = 0; $k < $s_size; $k++)
            {
                fwrite($f, $s[$i] . $s[$j] . $s[$k] . " ");
            }
            fwrite($f, "\r\n");
        }
        fwrite($f, "\r\n");
    }
    fclose($f);
     
    echo "end. check the file.";
}       

/*
run:

end. check the file.

*/

 



answered Oct 5, 2016 by avibootz
...