A PHP interview program question sharing

Source: Internet
Author: User
Compile a function for programming ). The language we use in our work is PHP. I hope you can answer in PHP. If you have any difficulties, you can use other languages. (For example, C #, Java, C ++, Python, Perl, Ruby, etc.) functions must be as follows: Enter the parameter-a string and return a string. The input is an English sentence, only English

Compile a function for programming ). The language we use in our work is PHP. I hope you can answer in PHP. If you have any difficulties, you can use other languages. (For example, C #, Java, C ++, Python, Perl, Ruby, etc.) functions must be as follows: Enter the parameter-a string and return a string. The input is an English sentence, only English

Programming questions
Compile a function ).
The language we use in our work is PHP. I hope you can answer in PHP. If you have any difficulties, you can use other languages. (Such as C #, Java, C ++, Python, Perl, Ruby, etc)
Function requirements are as follows:
Input parameter-a string to return a string.
The input is an English sentence, only English text (a-z, A-Z), each word is only a space lattice, front and back no space.
The returned result is to reverse the alphabetic order of each word, but the order of words and the uppercase and lowercase positions of letters remain unchanged.

Example:
Input parameters
This is an Apple on eBay
Return
Siht si na Elppa no yAbe
(For example, because eBay is the second letter in upper case, keep the second letter in upper case after being reversed .)

My program:

 $value){$str_arr[$key] = getNewStrExtra($value);}$new_str = implode(' ',$str_arr);return $new_str;}function getNewStrExtra($str){$length = strlen($str);for($i = 0;$i<$length;$i++){$extra_arr[] = substr($str, $i , 1);}foreach ($extra_arr as $key => $value) {$ord_v = ord($value);if($ord_v >= 60 && $ord_v <=90){$flag = $key;}}$return_arr = array_reverse($extra_arr);foreach ($return_arr as $key => $value) {$return_arr[$key] = strtolower($value);}if(isset($flag)){$return_arr[$flag] = strtoupper($return_arr[$flag]);}$return_str = implode('', $return_arr);return $return_str;}$str='This is an Apple on eBay';echo getNewStr($str);?>

Hope you can share it in a better and more efficient way!

Original article address: Share a PHP interview program question. Thank you for sharing it with me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.