fork(2) download
  1. <?php
  2.  
  3.  
  4. $bills = [500, 100];
  5. $totalBills = [5, 5, 5, 5];
  6. $rndCombination = [0, 0, 1, 5];
  7.  
  8. print_r($rndCombination);
  9.  
  10. function nextCombination($total, $combination){
  11. if($total == $combination){
  12. return 'Максимальная комбинация.';
  13. }
  14. $N = count($total) - 1;
  15. for($N; $N>0; $N--){
  16. if($combination[$N] < $total[$N]){
  17. $combination[$N] += 1;
  18. break;
  19. }
  20. else{
  21. $combination[$N] = 0;
  22. }
  23. }
  24. return $combination;
  25. }
  26.  
  27. print_r(nextCombination($totalBills, $rndCombination));
Success #stdin #stdout 0.02s 26320KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 0
    [1] => 0
    [2] => 1
    [3] => 5
)
32Array
(
    [0] => 0
    [1] => 0
    [2] => 2
    [3] => 0
)