Find minimum number of currency notes and values that sum to given amount | function to count and prcurrency notes ; count notes using Greedy approach ; Print notes ; Driver Code
< ? php function countCurrency ( $ amount ) { $ notes = array ( 2000 , 500 , 200 , 100 , 50 , 20 , 10 , 5 , 1 ) ; $ noteCounter = array ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ; for ( $ i = 0 ; $ i < 9 ; $ i ++ ) { if ( $ amount >= $ notes [ $ i ] ) { $ noteCounter [ $ i ] = intval ( $ amount / $ notes [ $ i ] ) ; $ amount = $ amount - $ noteCounter [ $ i ] * $ notes [ $ i ] ; } } echo ( " Currency ▁ Count ▁ - > " . " STRNEWLINE " ) ; for ( $ i = 0 ; $ i < 9 ; $ i ++ ) { if ( $ noteCounter [ $ i ] != 0 ) { echo ( $ notes [ $ i ] . " : " ▁ . ▁ $ noteCounter [ $ i ] ▁ . ▁ " " } } } $ amount = 868 ; countCurrency ( $ amount ) ; ? >