<small id='OEZBA'></small><noframes id='OEZBA'>

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

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

        如何简化嵌套的 php 数组?

        时间:2023-09-21
      2. <tfoot id='CxSlz'></tfoot>
            <tbody id='CxSlz'></tbody>

            <small id='CxSlz'></small><noframes id='CxSlz'>

            <legend id='CxSlz'><style id='CxSlz'><dir id='CxSlz'><q id='CxSlz'></q></dir></style></legend>

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

              • <bdo id='CxSlz'></bdo><ul id='CxSlz'></ul>
                  本文介绍了如何简化嵌套的 php 数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在编写一个 php Web 应用程序,其中有一个类似于以下内容的嵌套数组:

                  I'm writing a php web application where I have a nested array which looks similar to the following:

                  $results = array(
                          array(
                              array(
                                  'ID' => 1,
                                  'Name' => 'Hi'
                              )
                          ),
                          array(
                              array(
                                  'ID' => 2,
                                  'Name' => 'Hello'
                              )
                          ),
                          array(
                              array(
                                  'ID' => 3,
                                  'Name' => 'Hey'
                              )
                          )
                      );
                  

                  目前这意味着当我想使用 ID 字段时,我必须调用 $results[0][0]['ID'] 这相当低效,并且有多个数组一百条记录很快变得混乱.我想缩小数组,以便我可以调用 $results[0]['ID'] 代替.

                  Currently this means that when I want to use the ID field I have to call $results[0][0]['ID'] which is rather inefficient and with an array of over several hundred records becomes messy quickly. I would like to shrink the array down so that I can call $results[0]['ID'] instead.

                  我的理解是,使用 foreach 循环遍历数组中的每一行并更改格式的函数将是更改 $results 数组格式的最佳方法,但是我很难理解在 foreach 循环拥有每个初始数组后要做什么.

                  My understanding is that a function that uses a foreach loop to iterate through each row in the array and change the format would be the best way to go about changing the format of the $results array but I am struggling to understand what to do after the foreach loop has each initial array.

                  这是我目前的代码:

                  public function filterArray($results) {
                      $outputArray = array();
                  
                      foreach ($results as $key => $row) {
                  
                      }
                  
                      return $outputArray;
                  }
                  

                  谁能提出最有效的方法来实现我所追求的目标?

                  Would anyone be able to suggest the most effective way to achieve what I am after?

                  谢谢:)

                  推荐答案

                  只需使用 call_user_func_array as

                  Simply use call_user_func_array as

                  $array = call_user_func_array('array_merge', $results);
                  print_r($array);
                  

                  演示

                  这篇关于如何简化嵌套的 php 数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何将多个数组插入到数据库中? 下一篇:php函数没有从foreach中的MySQL查询返回所有结果

                  相关文章

                  最新文章

                    <tfoot id='n0MT0'></tfoot>

                      <legend id='n0MT0'><style id='n0MT0'><dir id='n0MT0'><q id='n0MT0'></q></dir></style></legend>

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

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