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

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

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

      PHP二維數組轉HTML

      PHP two dimensional array into HTML(PHP二維數組轉HTML)

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

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

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

              <tfoot id='HpTuc'></tfoot>
                <tbody id='HpTuc'></tbody>

                本文介紹了PHP二維數組轉HTML的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                一個簡單的谷歌搜索將揭示多種使用 PHP 將二維數組轉換為 HTML 的解決方案.不幸的是,這些都沒有我正在尋找的答案.

                A simple Google search will reveal a multitude of solutions for converting a two dimension array into HTML using PHP. Unfortunately none of these has the answers I am looking for.

                我想要一段將數組轉換為 HTML 表格的通用代碼.大多數例子出錯的地方是他們假設程序員知道表的字段的名稱.我希望這段代碼是通用的,這樣即使我不知道字段的名稱,我也可以使用它.

                I want a generic piece of code that converts an array into a HTML table. Where most examples go wrong is that they assume the programmer knows the name of the table's fields . I want this code to be generic such that I can use it even if I do not know the name of the fields.

                我可以看到我需要兩個循環.一個嵌套在另一個里面.鑒于我不知道密鑰,我不確定如何獲取值.

                I can see I need two loops. One nested inside of the other. What I am not sure of is how to get the values out given I don't know the keys.

                最終結果有望輸出這樣的html:

                The end result will hopefully output html something like this:

                <th>
                  <td>x/y</td>
                  <td> x1 </td>
                  <td> x2 </td>
                </th>
                <tr>
                  <td>y1</td>
                  <td> x1y1 </td>
                  <td> x2y1 </td>
                </tr>
                <tr>
                  <td>y2</td>
                  <td> x1y2 </td>
                  <td> x2y2 </td>
                </tr>
                

                請記住,我想要一個通用且簡單的解決方案.我希望這很清楚.

                Please remember I want a generic and simple solution. I hope this is clear.

                推薦答案

                下面的代碼將遍歷數組的兩個維度,并將它們變成一個表格.不管 key 是什么,你都會得到它的可視化表示.如果它們確實有鍵名而不僅僅是索引,則這些值將分別在$key$subkey 中可用.所以如果你需要它們,你可以擁有它們.

                The following code will look through the two dimensions of the array and make them into a table. Regardless of what the key may be, you will get a visual representation of it. If they do have key name and not just an index, the values will be available in $key and $subkey respectively. So you have them if you need them.

                代碼:

                $myarray = array("key1"=>array(1,2,3,4),
                                 "key2"=>array(2,3,4,5),
                                 "key3"=>array(3,4,5,6),
                                 "key4"=>array(4,5,6,7)); //Having a key or not doesn't break it
                $out  = "";
                $out .= "<table>";
                foreach($myarray as $key => $element){
                    $out .= "<tr>";
                    foreach($element as $subkey => $subelement){
                        $out .= "<td>$subelement</td>";
                    }
                    $out .= "</tr>";
                }
                $out .= "</table>";
                
                echo $out;
                

                結果:

                如果您想將鍵視為標題,可以在 echo "

                "; 行之后添加此代碼:

                If you want to see the keys as headings, you could add this code after the echo "<table>"; line:

                echo "<tr>";
                foreach($myarray as $key => $element) echo "<td>$key</td>";
                echo "</tr>";
                

                導致:

                這篇關于PHP二維數組轉HTML的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                相關文檔推薦

                Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                PHP PDO ODBC connection(PHP PDO ODBC 連接)
                Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                  <tfoot id='O3UU2'></tfoot>

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

                    <tbody id='O3UU2'></tbody>

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

                        <i id='O3UU2'><tr id='O3UU2'><dt id='O3UU2'><q id='O3UU2'><span id='O3UU2'><b id='O3UU2'><form id='O3UU2'><ins id='O3UU2'></ins><ul id='O3UU2'></ul><sub id='O3UU2'></sub></form><legend id='O3UU2'></legend><bdo id='O3UU2'><pre id='O3UU2'><center id='O3UU2'></center></pre></bdo></b><th id='O3UU2'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='O3UU2'><tfoot id='O3UU2'></tfoot><dl id='O3UU2'><fieldset id='O3UU2'></fieldset></dl></div>
                          主站蜘蛛池模板: 成人午夜毛片 | 黄片毛片免费观看 | 欧美自拍日韩 | jlzzxxxx18hd护士| 日韩一区在线播放 | 婷婷久久一区 | 91p在线观看 | 国产精品成人在线观看 | 人人干人人干人人 | 亚洲巨乳自拍在线视频 | 精品国产一区二区三区在线观看 | 国产福利91精品一区二区三区 | 亚洲 日本 欧美 中文幕 | 91在线精品秘密一区二区 | 亚洲二区在线观看 | 91精品国产综合久久久久 | 全免一级毛片 | 欧美精品一区二区在线观看 | 91精品一区二区三区久久久久久 | 免费亚洲一区二区 | 天天综合国产 | 性一交一乱一伦视频免费观看 | 9999久久 | 精品欧美乱码久久久久久 | 精品成人在线观看 | 国产精品国产三级国产aⅴ入口 | 男人天堂久久 | 最新国产在线 | 欧美日韩精品国产 | 久久久久久综合 | 精品天堂| 国产欧美久久精品 | 91免费观看在线 | 日韩免费福利视频 | 天堂av在线影院 | 国产精品揄拍一区二区 | 亚洲精品一区二区网址 | av在线一区二区三区 | 99久久99| 国产成人精品久久 | 中文字幕一区在线观看视频 |