<?php
 
error_reporting(-1);
 
$amount = 54500;
 
$bills = array(
	100    =>    23,
	500    =>    5,
	1000   =>    0,
	5000   =>    200
);
$bills = array_reverse($bills, TRUE);
$array = array();
echo "Сумма: $amount\n";
function  giveMoney($bills, $amount){
        if ($amount > 0 and $amount % 100 == 0) {
	foreach ($bills as $nominal => $value) {
		$countBanknote = floor($amount / $nominal);
                 if($amount >= $nominal and $countBanknote <= $value) {
	     	$value = $value - $countBanknote;
	     	$amount = $amount % $nominal;
	     	$return = "{$nominal}x{$countBanknote}";
	     	$array[] = $return;
	     }if($value == 0 and $countBanknote != 0) {
	     }
	     if($amount >= $nominal and $countBanknote > $value and $value != 0) {
	     	$countBanknote = $value;
	     	$sum = $nominal * $countBanknote;
	     	$amount = $amount % $sum;
	     	$return = "{$nominal}x{$countBanknote}";
	     	$array[] = $return;
	     }
	     
            }
        $array = implode(" ", $array);
        echo "Выдача возможна, число купюр:\n$array\n";
        }if($amount < 0) {
	echo"Выдача невозможна: сумма меньша нуля.\n";
        }if($amount % 100 != 0) {
	echo"Выдача невозможна: Сумма не кратна 100.\n";
   }
}
giveMoney($bills, $amount);