<?php

error_reporting(-1);

$bills = array(500, 100);
$totalBills = array(5, 2);
$rndCombination = array(2, 1);

function nextCombination($total, $combination){
	if($combination[0] == $total[0] && $combination[1] == $total[1] ){
		echo "Последняя комбинация:";
		print_r($combination);
		exit();
	}
	if($combination[0] > $total[0] || $combination[1] > $total[1]){
		echo "Введенная комбинация некорректна.";
		exit();
	}
	if($combination[1] < $total[1]){
		$combination[1]++;	
	}
	else{
		$combination[1] = 0;
		$combination[0]++;
	}
	print_r($combination);
}

echo nextCombination($totalBills, $rndCombination);