I have a n-values array:
$input = array( object_a, object_b, object_c, ..., object_n );</code>
I try to find the name of the function which produces this output:
$output = array(
array( object_a ), array( object_b ), ..., array( object_n ),
array( object_a, object_b ), array( object_a, object_c ), ..., array( object_a, object_n ),
array( object_b, object_c ), ..., array( object_b, object_n ),
...
array( object_a, object_b, object_c), ..., array( object_a, object_b, object_n),
...
array( object_a, object_b, object_c, ..., object_n)
);
It looks like cartesian product, but it was not.
I try to program this function, and I successfully create this following part of my results, but I am stuck with 'middle' distribution:
$output = array(
array( object_a ), array( object_b ), ..., array( object_n ),
array( object_a, object_b, object_c, ..., object_n)
);
I think middle part can be produce with function recursive call, but I have no clues on how to do it.
Thank you
Here is the beginning of my function:
/**
*
* @param array $array this input array
* example:
* $array = array(
* A, B, C
* );
*
* @return array the result array
* example:
* $result = array(
* array( A ), ok
* array( B ), ok
* array( C ), ok
* array( A, B ),
* array( A, C ),
* array( B, C ),
* array( A, B, C ) ok
* )
*/
private function distribute($array)
{
$result = array();
if (is_array($array)) {
// add array( 'A', 'B', 'C' ) to result
$result[] = $array;
if (count($array)>1) {
// add array( 'A' ), array( 'B' ), array( 'C' ) to result
foreach ($array as $value) {
$result[] = array($value);
}
// help me to complete this function
}
}
return $result;
}