久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

  • <tfoot id='LTnXI'></tfoot>
      <bdo id='LTnXI'></bdo><ul id='LTnXI'></ul>
  • <legend id='LTnXI'><style id='LTnXI'><dir id='LTnXI'><q id='LTnXI'></q></dir></style></legend>
  • <i id='LTnXI'><tr id='LTnXI'><dt id='LTnXI'><q id='LTnXI'><span id='LTnXI'><b id='LTnXI'><form id='LTnXI'><ins id='LTnXI'></ins><ul id='LTnXI'></ul><sub id='LTnXI'></sub></form><legend id='LTnXI'></legend><bdo id='LTnXI'><pre id='LTnXI'><center id='LTnXI'></center></pre></bdo></b><th id='LTnXI'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='LTnXI'><tfoot id='LTnXI'></tfoot><dl id='LTnXI'><fieldset id='LTnXI'></fieldset></dl></div>

        如何在 while 循環(huán)中填充數(shù)組并在每次迭代中獲得

        How do I fill an array inside a while loop and get new scope each iteration?(如何在 while 循環(huán)中填充數(shù)組并在每次迭代中獲得新范圍?)
          <bdo id='IShx2'></bdo><ul id='IShx2'></ul>
          <i id='IShx2'><tr id='IShx2'><dt id='IShx2'><q id='IShx2'><span id='IShx2'><b id='IShx2'><form id='IShx2'><ins id='IShx2'></ins><ul id='IShx2'></ul><sub id='IShx2'></sub></form><legend id='IShx2'></legend><bdo id='IShx2'><pre id='IShx2'><center id='IShx2'></center></pre></bdo></b><th id='IShx2'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='IShx2'><tfoot id='IShx2'></tfoot><dl id='IShx2'><fieldset id='IShx2'></fieldset></dl></div>
            <tbody id='IShx2'></tbody>

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

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

                  <tfoot id='IShx2'></tfoot>

                1. 本文介紹了如何在 while 循環(huán)中填充數(shù)組并在每次迭代中獲得新范圍?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  問題是我只得到來自表的最后一個(gè)值.我認(rèn)為這是因?yàn)槲以趯?shù)組的值引用到同一個(gè)對(duì)象的同時(shí)構(gòu)建數(shù)組,并且它一直在變化.我知道 while 循環(huán)不會(huì)為每次迭代創(chuàng)建一個(gè)新的范圍,問題.

                  The problem is that I get only the last value comming from the Table. I think its because I am building the array while referencing its values to the same object, and it keeps changing. I know while loop doesnt create a new scope for each iteration which IS the problem.

                  為每次迭代獲得新范圍的最佳方法是什么?

                  代碼:

                      $namesArray= array();
                          while ($row=mysql_fetch_array($result))
                          {
                          $nameAndCode->code = $row['country_code2'];
                          $nameAndCode->name = $row['country_name'];           
                          array_push($namesArray,$nameAndCode);
                  
                  
                          } 
                  return $namesArray;
                  

                  推薦答案

                  您需要在每次迭代時(shí)創(chuàng)建一個(gè)新對(duì)象:

                  You need to create a new object on each iteration:

                  while ($row=mysql_fetch_array($result))
                  {
                      $nameAndCode = new stdClass;
                      $nameAndCode->code = $row['country_code2'];
                      $nameAndCode->name = $row['country_name'];           
                      $namesArray[] = $nameAndCode;
                  } 
                  

                  否則,您將一遍又一遍地引用同一個(gè)對(duì)象,而只會(huì)覆蓋其值.

                  Otherwise you're referencing the same object over and over, and just overwriting its values.

                  如果你不需要對(duì)象,你也可以用數(shù)組來做到這一點(diǎn):

                  You also can do this with arrays if you don't require objects:

                  while ($row=mysql_fetch_array($result))
                  {
                      $nameAndCode = array();
                      $nameAndCode['code'] = $row['country_code2'];
                      $nameAndCode['name'] = $row['country_name'];           
                      $namesArray[] = $nameAndCode;
                  } 
                  

                  或者更簡(jiǎn)潔:

                  while ($row=mysql_fetch_array($result))
                  {
                      $namesArray[] = array( 
                          'code' => $row['country_code2'],
                          'name' => $row['country_name']
                      );
                  } 
                  

                  這篇關(guān)于如何在 while 循環(huán)中填充數(shù)組并在每次迭代中獲得新范圍?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準(zhǔn)備好的語句amp;foreach 循環(huán))
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個(gè)服務(wù)器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識(shí)別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個(gè)參數(shù))
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結(jié)果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“l(fā)ocalhost的訪問被拒絕)

                  1. <legend id='CdYu2'><style id='CdYu2'><dir id='CdYu2'><q id='CdYu2'></q></dir></style></legend>

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

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

                          <tfoot id='CdYu2'></tfoot>
                          1. 主站蜘蛛池模板: 日日操网站 | 亚洲精品中文字幕在线 | 日韩亚洲视频 | 精品视频免费在线 | 久久久网 | 一区二区精品在线 | 久久久久久国产免费视网址 | 久久国产欧美日韩精品 | 国产成人99久久亚洲综合精品 | 超碰在线人人 | 日韩第一页 | 日韩精品免费视频 | 5060网一级毛片 | 91丨九色丨国产在线 | 久久精品 | 国产精品久久久久久久久动漫 | 亚洲精品www久久久 www.蜜桃av | 日韩在线不卡视频 | 国产精品久久久久久久免费大片 | 久久免费精品 | 99这里只有精品视频 | 国产精品久久久久久婷婷天堂 | 精品视频久久久久久 | 99一级毛片| 爱爱视频网| 天天综合91 | 色爱综合网 | 国产美女一区 | 视频二区 | 色黄爽 | 夜操| 国产成人精品久久久 | 亚洲欧美久久 | 国产成人综合一区二区三区 | 色综合久久天天综合网 | 国产日产精品一区二区三区四区 | 亚洲国产一区视频 | 国产精品一区二区在线免费观看 | 亚洲国产精品99久久久久久久久 | 亚洲一区二区三区四区视频 | 国产91亚洲精品一区二区三区 |