<?php
error_reporting(-1);
$amount = 4100;
$rest   = $amount;
/*запас наличных*/
$bills = array(
    100 => 20,
    500 => 1,
    1000 => 4,
    5000 => 11
);
$n=count($bills)-1;
$b=range(0, $n);
$comb=array_combine($b, $bills);
$i=0;
foreach($bills as $key=> $value){
	$bills2[$i]=$key;
	++$i;
}

$text="";


for ($i = $n; $i >= 0; --$i) {
  if($comb[$i]==0){
  	continue;
  }
    $money = floor($rest / $bills2[$i]);
    if ($money > $comb[$i]) {
        $money = $comb[$i];
    }
    $rest = $rest - ($money * $bills2[$i]);
    
    $text = $text . $money . " X " . $bills2[$i] . "\t";
}

if ($rest == 0) {
    echo "сумма $amount \n выдано купюр: " . $text;
} else {
    echo "выдача невозможна";
}