<bdo id='nXt5r'></bdo><ul id='nXt5r'></ul>
  • <tfoot id='nXt5r'></tfoot>

    1. <i id='nXt5r'><tr id='nXt5r'><dt id='nXt5r'><q id='nXt5r'><span id='nXt5r'><b id='nXt5r'><form id='nXt5r'><ins id='nXt5r'></ins><ul id='nXt5r'></ul><sub id='nXt5r'></sub></form><legend id='nXt5r'></legend><bdo id='nXt5r'><pre id='nXt5r'><center id='nXt5r'></center></pre></bdo></b><th id='nXt5r'></th></span></q></dt></tr></i><div id='nXt5r'><tfoot id='nXt5r'></tfoot><dl id='nXt5r'><fieldset id='nXt5r'></fieldset></dl></div>

      1. <small id='nXt5r'></small><noframes id='nXt5r'>

      2. <legend id='nXt5r'><style id='nXt5r'><dir id='nXt5r'><q id='nXt5r'></q></dir></style></legend>

        如何将 PHP 数组编码为 JSON 数组,而不是对象?

        How do I encode a PHP array to a JSON array, not object?(如何将 PHP 数组编码为 JSON 数组,而不是对象?)

            <legend id='bMllq'><style id='bMllq'><dir id='bMllq'><q id='bMllq'></q></dir></style></legend>
              <bdo id='bMllq'></bdo><ul id='bMllq'></ul>

                  <tbody id='bMllq'></tbody>
              1. <small id='bMllq'></small><noframes id='bMllq'>

                <i id='bMllq'><tr id='bMllq'><dt id='bMllq'><q id='bMllq'><span id='bMllq'><b id='bMllq'><form id='bMllq'><ins id='bMllq'></ins><ul id='bMllq'></ul><sub id='bMllq'></sub></form><legend id='bMllq'></legend><bdo id='bMllq'><pre id='bMllq'><center id='bMllq'></center></pre></bdo></b><th id='bMllq'></th></span></q></dt></tr></i><div id='bMllq'><tfoot id='bMllq'></tfoot><dl id='bMllq'><fieldset id='bMllq'></fieldset></dl></div>

                  <tfoot id='bMllq'></tfoot>
                  本文介绍了如何将 PHP 数组编码为 JSON 数组,而不是对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试对从 Zend_DB 查询返回的数组进行 json_encode.

                  I am trying to json_encode an array which is returned from a Zend_DB query.

                  var_dump 给出:(手动添加 0 个成员不会改变图片.)

                  var_dump gives: (Manually adding 0 member does not change the picture.)

                  array(3) {
                    [1]=>
                    array(3) {
                      ["comment_id"]=>
                      string(1) "1"
                      ["erasable"]=>
                      string(1) "1"
                      ["comment"]=>
                      string(6) "test 1"
                    }
                    [2]=>
                    array(3) {
                      ["comment_id"]=>
                      string(1) "2"
                      ["erasable"]=>
                      string(1) "1"
                      ["comment"]=>
                      string(6) "test 1"
                    }
                    [3]=>
                    array(3) {
                      ["comment_id"]=>
                      string(1) "3"
                      ["erasable"]=>
                      string(1) "1"
                      ["comment"]=>
                      string(6) "jhghjg"
                    }
                  }
                  

                  编码后的字符串如下所示:

                  The encoded string looks like:

                  {"1":{"comment_id":"1","erasable":"1","comment":"test 1"},
                   "2":{"comment_id":"2","erasable":"1","comment":"test 1"},
                   "3":{"comment_id":"3","erasable":"1","comment":"jhghjg"}}
                  

                  我需要的是:

                  [{"comment_id":"1","erasable":"1","comment":"test 1"},
                  {"comment_id":"2","erasable":"1","comment":"test 1"},
                  {"comment_id":"3","erasable":"1","comment":"jhghjg"}]
                  

                  php.ini/json_encode 文档说它应该是什么样子.

                  Which is what the php.ini/json_encode documentation says it should look like.

                  推荐答案

                  您如何设置初始数组?

                  如果你这样设置:

                  array(
                   "1" => array(...),
                   "2" => array(...),
                  );
                  

                  那么你没有一个带有数字索引的数组,而是字符串,在 JS 世界中它被转换为一个对象.如果您没有设置严格的顺序(即从 0 而不是 1 开始),也会发生这种情况.

                  then you don't have an array with numeric indexes but strings, and that's converted to an object in JS world. This can happen also if you don't set a strict order (i.e. starting at 0 instead of 1).

                  然而,这是在黑暗中拍摄,因为我看不到您的原始代码:首先尝试在不使用键的情况下设置您的数组:

                  This is a shot in the dark, however, because I can't see your original code: try setting your array without using keys at all in the first place:

                  array(
                   array(...),
                   array(...),
                  );
                  

                  这篇关于如何将 PHP 数组编码为 JSON 数组,而不是对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    <tbody id='I3mLO'></tbody>
                      <tfoot id='I3mLO'></tfoot>
                      <i id='I3mLO'><tr id='I3mLO'><dt id='I3mLO'><q id='I3mLO'><span id='I3mLO'><b id='I3mLO'><form id='I3mLO'><ins id='I3mLO'></ins><ul id='I3mLO'></ul><sub id='I3mLO'></sub></form><legend id='I3mLO'></legend><bdo id='I3mLO'><pre id='I3mLO'><center id='I3mLO'></center></pre></bdo></b><th id='I3mLO'></th></span></q></dt></tr></i><div id='I3mLO'><tfoot id='I3mLO'></tfoot><dl id='I3mLO'><fieldset id='I3mLO'></fieldset></dl></div>
                      1. <small id='I3mLO'></small><noframes id='I3mLO'>

                        • <bdo id='I3mLO'></bdo><ul id='I3mLO'></ul>
                          <legend id='I3mLO'><style id='I3mLO'><dir id='I3mLO'><q id='I3mLO'></q></dir></style></legend>