<?php

error_reporting(-1);

$bills = [500, 100];
$totalBills = [5, 5, 5, 5];
$rndCombination = [0, 0, 1, 5];

print_r($rndCombination);

function nextCombination($total, $combination){
	if($total == $combination){
		return 'Максимальная комбинация.';
	}
	$N = count($total) - 1;
	for($N; $N>0; $N--){
		if($combination[$N] < $total[$N]){
			$combination[$N] += 1;
			break;
		}
		else{
			$combination[$N] = 0;
		}
	}
	return $combination;
}

print_r(nextCombination($totalBills, $rndCombination));