public static function arrayCartesian() {
        $args = func_get_args();

        if(count($args) == 0) {
            return [[]]; // array with empty array is expected "empty" result
        }

        $work      = array_shift($args);
        $cartesian = call_user_func_array(__METHOD__, $args);
        $result    = [];

        foreach($work as $value) {
            foreach($cartesian as $product) {
                $result[] = array_merge([$value], $product);
            }
        }

        return $result;
    }
public static function arrayCartesian() {
        $args = func_get_args();

        if(count($args) == 0) {
            return [[]]; // array with empty array is expected "empty" result
        }

        $work      = array_shift($args);
        $cartesian = call_user_func_array(__METHOD__, $args);
        $result    = [];

        foreach($work as $value) {
            foreach($cartesian as $product) {
                $result[] = array_merge([$value], $product);
            }
        }

        return $result;
    }
public static function arrayCartesian ( ) { $ args = func_get_args ( ) ; if ( count ( $ args ) == 0 ) { return [ [ ] ] ; // array with empty array is expected "empty" result } $ work = array_shift ( $ args ) ; $ cartesian = call_user_func_array ( __METHOD__ , $ args ) ; $ result = [ ] ; foreach ( $ work as $ value ) { foreach ( $ cartesian as $ product ) { $ result [ ] = array_merge ( [ $ value ] , $ product ) ; } } return $ result ; }
Calculate cartesian product of multiple arrays
@return multitype:multitype:
Calculate cartesian product of multiple arrays