Traverse all digits from right to left and check if any digit is smaller than previous .
while ( $ num ) { $ rem = $ num % 10 ; $ num = ( int ) $ num / 10 ; if ( $ rem > $ prev ) return false ; $ prev = $ rem ; } return true ; }