欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-06-08 10:41:26
...
原代码:
$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);

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

貌似最简单的是:

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

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

回复内容:

原代码:

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

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

貌似最简单的是:

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

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

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

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

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

相关标签: php yii