PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php $addends = []; $max_count = 3; $max_sum = 80; for($i=0; $i<$max_count; $i++) { // generate random value between 0 and $max_sum, but not grate when $max_value $value = rand(10, $max_sum); // echo "rand(0, min($max_value, $max_sum)) = $value \n"; // decrease $max_sum to $value $max_sum -= $value; // store value into array $addends[] = $value; } print_r($addends); print_r(array_sum($addends));
Show:  
Copy Clear