Home  >  Article  >  Backend Development  >  php按照数组长度排序,不改变位置算法,各位老师请帮忙,该如何处理

php按照数组长度排序,不改变位置算法,各位老师请帮忙,该如何处理

WBOY
WBOYOriginal
2016-06-13 13:33:35820browse

php按照数组长度排序,不改变位置算法,各位老师请帮忙

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->$arr = array('宫颈糜烂','治疗','治疗宫颈','宫颈','糜烂','如何治疗','如何','治宫颈','怎样','怎样治疗','宫糜');
function arrLenOrder_desc($a,$b)
{
    if (strlen($a) == strlen($b))  return 0;
    return (strlen(strip_tags($a)) 


------解决方案--------------------
换些数据不好吗? 全是女人病。
PHP code

$arr = array('宫颈糜烂','治疗','治疗宫颈','宫颈','糜烂','如何治疗','如何','治宫颈','怎样','怎样治疗','宫糜');
$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); <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn