J
J
justyork2016-11-15 19:48:01
PHP
justyork, 2016-11-15 19:48:01

How to do ascending recursion?

Hello everyone, tell me how to make a recursion from an array, in which the values ​​are in ascending order, example:
$arr = [1, 2, 3];
You should get the following

1
1 2
1 3
1 2 3
2
2 3
3

I am sure that the task is solved by elementary recursion, but something I don’t have enough brains for this.
At the input, the function must take a one-dimensional array ['a', 'b', 'c'], the output data must go with the same order as in the array, i.e. a, ab, abc, ac, b, bc, c

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2016-11-16
@jcmvbkbc

how to recurse from an array

Recursion is a method of solving a problem that uses itself to solve subproblems. An array is an array. You can't recurse from an array. You can print an array to the screen with a recursive function.
values ​​ascending
...
1 2
1 3
1 2 3

But it's not ascending. Ascending (lexicographically) would be
1 2
1 2 3
1 3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question