PHP sorted by array length, do not change the location algorithm, teachers please help, how to deal with

Source: Internet
Author: User
PHP sorted by array length, do not change the location algorithm, please help the teacher
PHP Code
  
   $arr = Array (' Cervical erosion ', ' treatment ', ' treatment of the cervix ', ' cervix ', ' erosion ', ' How to treat ', ' how ', ' How ' to cure the cervix ', ' how ', ' How to treat ', ' Palace of the Mi '); function Arrlenorder_desc ($a, $b) {    if (strlen ($a) = = 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 cervix, cure cervix, treatment, how, Gong, how, erosion, cervix/* But the result I want is (that is, if the length does not change the original order): *///cervical erosion, treatment of the cervix, how to treat, how to treat, cure the cervix, treatment, cervix, erosion, how, how, Gong


------Solution--------------------
Is it bad to change the data? All women are sick.
PHP code
 $arr = Array (' Cervical erosion ', ' treatment ', ' treatment of the cervix ', ' cervix ', ' erosion ', ' How to treat ', ' How ', ' cure the cervix ', ' how ', ' How to treat ', ' Palace of _k '); $a = 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.