Convert a sentence into its equivalent mobile numeric keypad sequence | Function which computes the sequence ; length of input string ; Checking for space ; Calculating index for each character ; Output sequence ; storing the sequence in array
< ? php function printSequence ( & $ arr , $ input ) { $ output = " " ; $ n = strlen ( $ input ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ input [ $ i ] == ' ▁ ' ) $ output = $ output + "0" ; else { $ position = ord ( $ input [ $ i ] ) - ord ( ' A ' ) ; $ output = $ output . $ arr [ $ position ] ; } } return $ output ; } $ str = array ( "2" , "22" , "222" , "3" , "33" , "333" , "4" , "44" , "444" , "5" , "55" , "555" , "6" , "66" , "666" , "7" , "77" , "777" , "7777" , "8" , "88" , "888" , "9" , "99" , "999" , "9999" ) ; $ input = " GEEKSFORGEEKS " ; echo printSequence ( $ str , $ input ) ; ? >