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

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

WBOY
Release: 2016-06-06 20:39:02
Original
865 people have browsed it

原代码:

<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>
Copy after login
Copy after login

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

貌似最简单的是:

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

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

回复内容:

原代码:

<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>
Copy after login
Copy after login

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

貌似最简单的是:

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

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

你先用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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template