Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Jan Galek
    @JanGalek

    <?php
    function workOutCombinations ($data, &$all = array(), $group = array(), $val = null, $i = 0) {
    if (isset($val)) {
    array_push($group, $val);
    }

    if ($i >= count($data)) {
        array_push($all, $group);
    } else {
        foreach ($data[$i] as $v) {
            workOutCombinations($data, $all, $group, $v, $i + 1);
        }
    }
    return $all;

    }

    $ar0 = array('a', 'b', 'c');
    $ar[1] = array('1', '2', '3');
    $ar[2] = array('red', 'green', 'blue');
    $ar[2] = array('cat', 'dog', 'fish');

    $combos = workOutCombinations($ar);
    print_r($combos);

    $array = [
    0 => [
    1 => 'value',
    2 => 'value',
    ],
    1 => [
    3 => 'value',
    4 => 'value',
    ],
    ];