Check if a number is jumbled or not | Function to check if a number is jumbled or not ; Single digit number ; Checking every digit through a loop ; All digits were checked ; Digit at index i ; Digit at index i - 1 ; If difference is greater than 1 ; Number checked ; - 1234 to be checked ; 287 to be checked
< ? php function checkJumbled ( $ num ) { if ( $ num / 10 == 0 ) return true ; while ( $ num != 0 ) { if ( $ num / 10 == 0 ) return true ; $ digit1 = $ num % 10 ; $ digit2 = ( $ num / 10 ) % 10 ; if ( abs ( $ digit2 - $ digit1 ) > 1 ) return false ; $ num = $ num / 10 ; } return true ; } $ num = -1234 ; if ( checkJumbled ( $ num ) ) echo " True ▁ STRNEWLINE " ; else echo " False ▁ STRNEWLINE " ; $ num = -1247 ; if ( checkJumbled ( $ num ) ) echo " True ▁ STRNEWLINE " ; else echo " False ▁ STRNEWLINE " ; ? >