I need to write a function which iterates through alphabet (a-z) like this:
(here is an example for a-c)
a
b
c
aa
ab
ac
ba
bb
bc
ca
cb
cc
aaa
aab
aac
... and so on. (until the word has 5 characters)
any idea how to do this? I guess I need some recursive function.
No need for recursion!
Why would you need recursion for this? It could be tail recursive (which means that it could just be done iteratitively). For e.g, here is a try in Python. You had tagged PHP, so if PHP has similar libraries you can try that or implement the corresponding functions in your code.
This is a quick recursive way to do it:
Explained: if it did not reach the maximum level to write out, it calls itself again. And it adds every character in a loop.
loopchars($n,1,'');
makes $n-th level iterations therefore the loop makes every level between 1 and 5.