php小白数组求解 根据某一个键值重新排序数组 给分100

WBOY
发布: 2016-06-23 13:28:26
原创
1060 人浏览过

这样一个json数组
[ {"id":"1","name":"21g","dis":"33"},
  {"id":"2","name":"21g","dis":"22"},
  {"id":"3","name":"21g","dis":"3"},
  {"id":"4","name":"21g","dis":"5"},
  {"id":"5","name":"21g","dis":"12"}]    
需要根据dis从小到大排序成
[{"id":"3","name":"21g","dis":"3"},
 {"id":"4","name":"21g","dis":"5"},
 {"id":"5","name":"21g","dis":"12"},
 {"id":"2","name":"21g","dis":"22"},
 {"id":"1","name":"21g","dis":"33"}]

求步骤详情  在线等      急!!!


回复讨论(解决方案)

$s =<<< TXT[ {"id":"1","name":"21g","dis":"33"},  {"id":"2","name":"21g","dis":"22"},  {"id":"3","name":"21g","dis":"3"},  {"id":"4","name":"21g","dis":"5"},  {"id":"5","name":"21g","dis":"12"}]    TXT;$a = json_decode($s, true);foreach($a as $v) $r[] = $v['dis'];array_multisort($r, $a);echo json_encode($a);
登录后复制
[{"id":"3","name":"21g","dis":"3"},{"id":"4","name":"21g","dis":"5"},{"id":"5","name":"21g","dis":"12"},{"id":"2","name":"21g","dis":"22"},{"id":"1","name":"21g","dis":"33"}]

谢谢谢谢!!  已经弄好了!

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!