i have function for combine number like this

function combin($mainArray, $size, $combinations = [])
    {
        if (empty($combinations)): $combinations = $mainArray; endif;

        if ($size == 1): return str_replace('-','',$combinations); endif;

        $newCombination = array();

        foreach ($mainArray as $key => $val):

            foreach ($combinations as $char):
                if(in_array($val, explode('-', $char))): continue; endif;
                $newCombination[] = $val . '-' . $char;
            endforeach;

        endforeach;

        return combin($mainArray, $size - 1, $newCombination);
    }

    $num = '1111111111';
    $num = str_split($num);
    //--//
    echo '<pre>';
    print_r(combin($num,4));
    echo '</pre>';

i have problem when i input number like this 1111111111
the result is like this and this result i wrong

Array
(
    [0] => 1
    [1] => 1
    [2] => 1
    [3] => 1
    [4] => 1
    [5] => 1
    [6] => 1
    [7] => 1
    [8] => 1
    [9] => 1
)

what i want the result is like this and this is the correct result

Array
(
    [0] => 1111
)

i hope someone can help me

Sorry, I'm not quite understanding what you are trying to accomplish.

On line 22, you are splitting the $num variable into an array, so the value of $num, after line 22 executes, is now:

Array
(
    [0] => 1
    [1] => 1
    [2] => 1
    [3] => 1
    [4] => 1
    [5] => 1
    [6] => 1
    [7] => 1
    [8] => 1
    [9] => 1
)

Then you're taking that array and passing it in along with a $size of 4. I'm not quite sure what combin() is supposed to do? Why is there recursion? What are combinations? What are you combining?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.