Before to start explaining my problem I know that most probably there're tons of script of example already available to cover my need, but honestly writing I wasn't able to catch exactly what I want.
My need is to compute a vector listing all the possible combinations of such matrix where the single value may be a key of the possibilities.
To better explain what you mean consider this example:
$start = 10;
$matrix = array(
10 => array(11,12,13),
11 => array(21,31,41),
13 => array(99,98,97),
41 => array(7,8,9)
)
What I need is to develop an algorithm capable to return a matrix of all the possible combinations considering that the values can be permuted only when the key exists. Or better (and again with an example) I would like to obtain an output like this:
$output = array(
[0] => array(10 , 11 , 21), //-- 21 is not a key so the 1st element contains only 3 values
[1] => array(10 , 11 , 31)
[2] => array(10 , 11 , 41 , 7)
[4] => array(10 , 11 , 41 , 8)
[5] => array(10 , 11 , 41 , 9)
[6] => array(10 , 12)
[7] => array(10 , 13 , 99)
[8] => array(10 , 13 , 98)
[9] => array(10 , 13 , 97)
);
Has anyone had a similar problem?