Heim  >  Artikel  >  Backend-Entwicklung  >  求一段优雅高效的数组排序算法

求一段优雅高效的数组排序算法

WBOY
WBOYOriginal
2016-06-06 20:39:02799Durchsuche

原代码:

<code>$web =List::Model()->findAll(array("condition"=>"id = 8}","order"=>"id asc"));
$webs='';

foreach($web as $k=>$v){
    foreach($v as $ks=>$vs){
    $webs[$k][$ks]=$vs;
    }
}

Response::json($webs);
</code>

求一段优雅高效的数组排序算法。

貌似最简单的是:

<code>$web =List::Model()->findAll(array("condition"=>"id = 8}","order"=>"id asc"));
Response::json(json_decode(CJSON::encode($web),TRUE)); 
</code>

不知道这么转换会不会有其它问题?

回复内容:

原代码:

<code>$web =List::Model()->findAll(array("condition"=>"id = 8}","order"=>"id asc"));
$webs='';

foreach($web as $k=>$v){
    foreach($v as $ks=>$vs){
    $webs[$k][$ks]=$vs;
    }
}

Response::json($webs);
</code>

求一段优雅高效的数组排序算法。

貌似最简单的是:

<code>$web =List::Model()->findAll(array("condition"=>"id = 8}","order"=>"id asc"));
Response::json(json_decode(CJSON::encode($web),TRUE)); 
</code>

不知道这么转换会不会有其它问题?

你先用markdown编辑下代码吧
我帮你展示下

<code>php</code><code>$web =List::Model()->findAll(array("condition"=>"id = 8}","order"=>"id asc")); 
$webs='';

foreach($web as $k=>$v){
    foreach($v as $ks=>$vs){ 
        $webs[$k][$ks]=$vs;
    } 
}

Response::json($webs);
</code>

http://www.cnblogs.com/imxiu/p/3474367.html

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn