Php is sorted by array length without changing the location algorithm. please help me. what should I do?

Source: Internet
Author: User
Php is sorted by the array length without changing the location algorithm. For more information, see PHPcode $ arr = array ('cervical erosion ', 'therapeutic', 'cervical Cup ', 'erosion ', 'How to treat', 'How to ', 'cure the cervix', 'who', 'How to treat ', 'Gong mi'); functionarrLenOrder_desc ($, $ B) {if (s php sorts by array length without changing the location algorithm. please help me
PHP code
  $ Arr = array ("cervical erosion", "treatment", "treatment cervix", "Cervix", "erosion", "how to treat", "how ', ' ', '',' '); function arrLenOrder_desc ($ a, $ B) {if (strlen ($) = strlen ($ B) return 0; return (strlen (strip_tags ($ a) <strlen (strip_tags ($ B )))? 1:-1;} usort ($ arr, "arrLenOrder_desc"); echo implode (",", $ arr);/* output * // how to treat cervical erosion, how to treat, treat the cervix, cure the cervix, treat, and treat the cervix. what should I do? erosion, cervix? * but the result I want is (that is, if the length is the same, it does not change the original sequence): * // cervical erosion, treatment of cervix, how to treat, how to treat, cure cervix, treatment, cervix, erosion, how, how, Gong Mi


------ Solution --------------------
Is it difficult to change some data? All women are ill.
PHP code
$ Arr = array ("cervical erosion", "treatment", "treatment cervix", "Cervix", "erosion", "how to treat", "how ', ' ', '',' '); $ a_k = array_keys ($ arr ); $ a_v = array_map (create_function ('$ item', 'Return strlen ($ item);'), $ arr); array_multisort ($ a_v, SORT_DESC, SORT_NUMERIC, $ a_k, SORT_ASC, SORT_NUMERIC, $ arr); echo implode (",", $ arr );

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.