Avoid memory overflow in a PHP function

0

Galera, I'm debuting here and I have the following problem: I created a function with a hint that I found right here in stackoverflow.

function DozenGenerate($game,$dozen) {
    $this->game = $game;
    $this->dozen = $dozen;
    if ($game === 0) {
        return array(array());
    }
    if (count($dozen) === 0) {
        return array();
    }
    if (count($dozen)< $game){
    }
    ob_start();
    $dozen_receive = $dozen[0];
    $dozen_compare = array_slice($dozen,1,count($dozen)-1);
    $dozenI = $this->DozenGenerate($game-1,$dozen_compare);
    for ($i = 0; $i < count($dozenI);$i++){
        array_splice($dozenI[$i],0,0,$dozen_receive);
    }
    ob_get_contents();
    $dozenII = $this->DozenGenerate($game,$dozen_compare);
    ob_end_flush();
    return array_merge($dozenI,$dozenII);
    }

Then I create a range and use the function:

$range = range(1,24);
$numbers = DozenGenerate(15,$range);
print_r($numbers);

When it generates very large unique combinations, it returns this error that would be natural:

Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 25165832 bytes) in C:\xampp\htdocs\netboloes\class\folk.php on line 44

I would like to know how to do the memory emptying so that the function keeps running, without returning this message, but rather to the array? I hope you can help me.

    
asked by anonymous 29.12.2017 / 09:04

0 answers