Find the largest number that can be formed with the given digits | Function to generate largest possible number with given digits ; sort the given array in descending order ; generate the number ; Driver code
< ? php function findMaxNum ( & $ arr , $ n ) { rsort ( $ arr ) ; $ num = $ arr [ 0 ] ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { $ num = $ num * 10 + $ arr [ $ i ] ; } return $ num ; } $ arr = array ( 1 , 2 , 3 , 4 , 5 , 0 ) ; $ n = sizeof ( $ arr ) ; echo findMaxNum ( $ arr , $ n ) ; ? >