Maximum number by concatenating every element in a rotation of an array | Function to print the largest number ; store the index of largest left most digit of elements ; Iterate for all numbers ; check for the the last digit ; check for the largest left most digit ; print the rotation of array ; print the rotation of array ; Driver Code
< ? php function printLargest ( $ a , $ n ) { $ max = -1 ; $ ind = -1 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ num = $ a [ $ i ] ; while ( $ num ) { $ r = $ num % 10 ; $ num = ( int ) $ num / 10 ; if ( $ num == 0 ) { if ( $ max < $ r ) { $ max = $ r ; $ ind = $ i ; } } } } for ( $ i = $ ind ; $ i < $ n ; $ i ++ ) echo $ a [ $ i ] ; for ( $ i = 0 ; $ i < $ ind ; $ i ++ ) echo $ a [ $ i ] ; } $ a = array ( 54 , 546 , 548 , 60 ) ; $ n = sizeof ( $ a ) ; printLargest ( $ a , $ n ) ; ? >