I have a .php file that gets data from SQL and then produces them as json array using json_encode. What I would like to know is, is it possible to sort them? or anything along those lines? Thanks
关注
码龄 粉丝数 原力等级 --
- 被采纳
- 被点赞
- 采纳率

已采纳
如何在php上对Json_encode进行排序?
收起
- 写回答
- 好问题 0 提建议
- 关注问题
微信扫一扫
点击复制链接分享
- 邀请回答
- 编辑 收藏 删除 结题
- 收藏 举报
1条回答 默认 最新
- 关注
码龄 粉丝数 原力等级 --
- 被采纳
- 被点赞
- 采纳率
douquan2023 2015-03-19 07:21关注You need to sort, order, group or whatever you like them in either the sql query or through array manipulation before using json_encode.
json_encode (as it is clear from its name) is only used for encoding the data, not sorting etc. Whatever you give it, it will just encode/serialize to json.
本回答被题主选为最佳回答 , 对您是否有帮助呢? 本回答被专家选为最佳回答 , 对您是否有帮助呢? 本回答被题主和专家选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏举报微信扫一扫
点击复制链接分享
编辑预览轻敲空格完成输入- 显示为
- 卡片
- 标题
- 链接
评论按下Enter换行,Ctrl+Enter发表内容
编辑
预览

轻敲空格完成输入
- 显示为
- 卡片
- 标题
- 链接
报告相同问题?
提交
- 2019-08-11 06:49回答 1 已采纳 The problem is json_encode can not access private properties. Here are some workarounds you could
- 2017-12-19 11:54回答 1 已采纳 As @LSerni said, I was implicitly assigning the encrypted id which is a string to the integer prop
- 2019-05-10 01:16回答 3 已采纳 You can add a second parameter to json_encode. This is called the JSON_PRETTY_PRINT constant: <
- 2021-04-23 01:51Python咖啡的博客 php关联数组排序后,用json_encode输出给前端,为什么顺序会发生变化?这是用file_put_contents函数写入到文件里的排序过的数组,顺序是对的。这是用echo json_encode()输出到前台的数据,顺序发生了变化。为什么呢...
- 2019-02-18 21:46回答 1 已采纳 I found the answer from another related question I posted on a different post. The errors array wa
- 2018-04-01 23:55回答 2 已采纳 I have checked its working fine with me. Please see below code: <?php $requests = '{"Monday":"
- 2015-05-07 00:47回答 4 已采纳 Your PHP starts like this: <html> <body> Whatever else it outputs after that, it is
- 2020-10-15 03:37例如,数组`array('18' => ..., '19' => ...)`会被编码为`{"18": ..., "19": ...}`,但数组`array(' 18' => ..., ' 19' => ...)`则会保持原样,因为在这里,数字键被识别为字符串,PHP不会对字符串进行排序。...
- 2019-03-05 10:24回答 1 已采纳 I found the problem. It wasn't in the code it was in the data returned from the SQL query. This ch
- 2016-05-26 01:30回答 2 已采纳 JSON_ERROR_RECURSION indicates that the data passed to json_encode() contains one or more recursiv
- 2011-10-29 02:46回答 2 已采纳 json_encode() has the (undocumented) habit of silently nulling properties that contain invalid (=
- 2021-04-09 04:52weixin_39782355的博客 php关联数组排序后,用json_encode输出给前端,为什么顺序会发生变化?这是用file_put_contents函数写入到文件里的排序过的数组,顺序是对的。这是用echo json_encode()输出到前台的数据,顺序发生了变化。为什么呢...
- 2020-10-26 11:10总结来说,从数据库获取数据,构建PHP数组,然后通过json_encode转换成JSON字符串,再将这个字符串传递给前端JavaScript处理,这个流程是Web开发中非常常见的数据交互方式。掌握这方面的知识能够帮助开发者更好地...
- 2017-08-09 02:44zNULLT的博客 简说PHP JSON问题(有序无序问题) 首先 什么是JSON: 通俗的说,它是一种数据的存储格式,就像PHP序列化后的字符串一样。它是一种数据描述。比如我们将一个数组序列化后存放,就可以很容易的反序列化后应 用。JSON...
- 2018-10-22 08:27张一丁的博客 json_encode 索引为数字,自动排序问题 使用son_encode 给前端返回数据,结果顺序不对,经debug调试,发现是json_encode 函数的问题; { "code": 0, "msg": "请求成功!", "...
- 2020-11-18 08:44鱼丸粗面1928的博客 PHP 下标不是以0开始的数组 json_encode 格式化会转为对象 遇到这种问题,很是麻烦。 例如: $array = array( '1'=>array( 'a'=>'red', 'b'=>'blue', 'c'=>'green' ), '3'=>array( 'd'=&...
- 2021-09-03 09:36一殊酒的博客 【代码】【前端开发】Laravel框架:JSON。
- 2021-10-26 13:39Calendo的博客 json_encode()在打包的时候,由于默认的编码方式让它解析中文是频频出错,总是给乱码,在查到大量的资料之后,我发现只要在json_encode($arr,JSON_UNESCAPED_UNICODE) 后面的参数加上,就可以完美解决乱码问题 ...
- 没有解决我的问题, 去提问
联系我们(工作时间:8:30-22:00)
400-660-0108kefu@csdn.net在线客服
- 京ICP备19004658号
- 经营性网站备案信息
公安备案号11010502030143
- 营业执照
- 北京互联网违法和不良信息举报中心
- 家长监护
- 中国互联网举报中心
- 网络110报警服务
- Chrome商店下载
- 账号管理规范
- 版权与免责声明
- 版权申诉
- 出版物许可证
- ©1999-2025北京创新乐知网络技术有限公司