Welcome back to shorltearner.com, we are starting a new series of PHP interview questions for beginners and experienced,so in previous post we learn, Write a PHP program to check if the bits of the two given positions of a number are same or notAdvertisement
In this post we see how to Converting words to numbers in PHP.
Also Read
Unable to create a directory a wordpress error
PHP program that multiplies corresponding elements of two given lists
PHP program to print out the multiplication table up to 6*6

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | <?php function word_digit($word) { $warr = explode(';',$word); $result = ''; foreach($warr as $value){ switch(trim($value)){ case 'zero': $result .= '0'; break; case 'one': $result .= '1'; break; case 'two': $result .= '2'; break; case 'three': $result .= '3'; break; case 'four': $result .= '4'; break; case 'five': $result .= '5'; break; case 'six': $result .= '6'; break; case 'seven': $result .= '7'; break; case 'eight': $result .= '8'; break; case 'nine': $result .= '9'; break; } } return $result; } echo word_digit("zero;three;five;six;eight;one")."\n"; echo word_digit("seven;zero;one")."\n"; ?> |
1 | 035681 701 |