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