-6

Its hard to explain this in the title

I have array of different value. lets say this is the array:

$char = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0");

how do I print every possible 3 char of this array. like start off...

aaa

aab

aac

and so on...

Kevin Kopf
  • 13,327
  • 14
  • 49
  • 66
Abdullah Salma
  • 560
  • 7
  • 20
  • 2
    Show us your effort please – B001ᛦ Feb 22 '18 at 13:01
  • @b001 I skipped math classes, now I regret this, I know that from 0-9, with 3 digits is 999 possibility, 36 char to gather how many possibility? I think i need to multiply 36 by 100. that result in 3600 possibility. so I for from 0 to 3600, and for each first chart will stay at 0 second 0 and third is going from 1 to 36 then second char with change from 0 to 1 and 3rd char with start counting again. I kind have long way to do it, but I need the possibility badly. – Abdullah Salma Feb 22 '18 at 13:06
  • @KunalAwasthi I need to know what is the possibility of 36 char together is it 3600? I really don't know. I know how to loop. – Abdullah Salma Feb 22 '18 at 13:07
  • @AbdullahSalma 46656 number of possible combinations according to me by searching on google.. try to search the problem over google or on your fav search engine. – Kunal Awasthi Feb 22 '18 at 13:11
  • A little clue: Permutations without repetition: 42840. Permutation allowing repetition: 46656 – Stuart Feb 22 '18 at 13:13
  • @Stuart yes exactly what I needed. "Permutations". – Abdullah Salma Feb 25 '18 at 08:11

2 Answers2

0

You need to loop 3's to find your desire output.

$char = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0");
$length = count($char);
for($i = 0; $i < $length; $i++)
    for($j = 0; $j < $length; $j++)
        for($k = 0; $k < $length; $k++)
            echo $char[$i].$char[$j].$char[$k]."<br/>";

Output:

aaa
aab
aac
aad
aae
aaf
aag
aah
aai
...
Murad Hasan
  • 9,565
  • 2
  • 21
  • 42
0

Here is the example of possible two alphanumerics

<?php
$start = base_convert("10",36,10);
$end = base_convert("zz",36,10);
for($start;$start <= $end;$start++){
  echo base_convert($start,10,36)."\n";
}
?>

Live Demo

You can start from 100 to zzz to get all possible digits of three albhanumeric.

Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109