Divide a number into two parts | Function to print the two parts ; Find the position of 4 ; If current character is not '4' but appears after the first occurrence of '4' ; Print both the parts ; Driver code
< ? php function twoParts ( $ str ) { $ flag = 0 ; $ a = " " ; for ( $ i = 0 ; $ i < strlen ( $ str ) ; $ i ++ ) { if ( $ str [ $ i ] == '4' ) { $ str [ $ i ] = '3' ; $ a . = '1' ; $ flag = 1 ; } else if ( $ flag ) $ a . = '0' ; } echo $ str . " ▁ " . $ a ; } $ str = "9441" ; twoParts ( $ str ) ; ? >