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 );