1

I am new to PHP and I need your help. :)

Here is the scenario: I need "6" random numbers from the range "1 to 50" which when add up should give a total of "111". How do I print out all possible combinations?

function mynumbers($min, $max, $quantity) {
    $numbers = range($min, $max);
    shuffle($numbers);
    return array_slice($numbers, 0, $quantity);
}

$nums = mynumbers(1,50,6);
$sum = array_sum($nums);

if($sum == 111){
    sort($nums);
    foreach($nums as $n){
        echo $n .' '; 
    }
}

Thanks

wogsland
  • 9,106
  • 19
  • 57
  • 93
Ravi Mota
  • 21
  • 1
  • Specifically [this answer from the above link for PHP](http://stackoverflow.com/a/9024082/2053706) – Ari Feb 02 '17 at 01:48

0 Answers0