Home >Backend Development >PHP Tutorial >求一段优雅高效的数组排序算法

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

WBOY
WBOYOriginal
2016-06-06 20:39:02873browse

原代码:

<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

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