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