I wish to create all permutations of all digits from a function.

For e.g. I have the array [1,2,3].
I would like the function to first print all possible permutations of 1 digit numbers:

1
2
3

then all possible permutations of 2-digit numbers(duplicates like 11, 22, 33 included)

11
12
13
21
22
23
31
32
33

and similarly for the 3 digit numbers.

I want to include all sort of possible permutations(11, 111, 222 etc.) up to the number of digits in the array, like in this example, I would like to have all permutations up to 3 digits.
How can I write it?