簡體   English   中英

PHP如何探索多維數組

[英]PHP how to explore a multidimentional array

我已經閱讀了高級幫助,對不起,但我不理解該編輯器!!!

我創建了一個多維像:

[YYY] => Array
     (
         [0] => 11.12
         [1] => 22.775000000
         [2] => 33.895
         [AABB] => Array
             (
                 [0] => 22.12
                 [1] => 12.23000000
                 [2] => 23.895
             )
     )
[ZZZ] => Array
     (
         [0] => 1.12
         [1] => 33.775000000
         [2] => 44.895
         [NNNN] => Array
             (
                 [0] => 23.30
                 [1] => .000000000
                 [2] => 997.3
             )

YYY和ZZZ是主要的“記錄”。 YYY確實有一個子記錄AABB,而ZZZ確實有一個子記錄NNNN。 在此示例中,它們只有一個子記錄,但是每個主記錄可以有一個或多個子記錄。

結果應該是這樣的(抱歉,我不了解編輯器,盡管如果我閱讀了高級幫助,它應該與| s和-s ???一起使用):

  <table> <tr> <th> kolom 1</th><th>Kolom 2</th><th>Kolom 4</th><th>Kolom 4</td> </tr> <tr> <td>YYY</td><td>11.12</td><td>22.775000000</td><td>33.895</td> </tr> <tr> <td>- AABB</td><td>22.12</td><td>12.23000000</td><td>23.895</td> </tr> <tr> <td>ZZZ</td><td>1.12</td><td>33.775000000</td><td>44.895</td> </tr> <tr> <td>- NNNN</td><td>23.30</td><td>.000000000</td><td>997.3</td> </tr> </table> 

我希望清楚我想要什么。 抱歉,版式很抱歉,但我不明白該編輯器的工作原理。

我正在嘗試像這樣的foreach循環(為了簡化起見,我對其進行了簡化):

foreach($aMarktWaardeExposure as $sLevel3 => $aLevel4) { 
        echo '<td><strong>'.$sLevel3.'</strong></td>'; //main record
        foreach($aLevel4 as $sLevel4) { 
                echo $sLevel4.'<br />'; //Sub record
        } 
}

我希望有人能幫助我。

謝謝,

尼科

也許是這樣的:

    <?php 

$array = [
    'YYY' => [
        0 => 11.12,
        1 => 22.775000000,
        2 => 33.895,
        'AABB' => [
            0 => 22.12,
            1 => 12.23000000,
            2 => 23.895,

        ]
    ], 
    'ZZZ' => [
        0 => 1.12,
        1 => 33.775000000,
        2 => 44.895,
        'NNNN' => [
            0 => 23.30,
            1 => .000000000,
            2 => 997.3
        ]
    ]
];
?> 
<style type="text/css">
table td{
    border: 1px solid red;
}
</style>

<table>
    <?php foreach($array as $row): ?>
        <tr>
            <?php foreach($row as $cell): ?>
                <td>
                    <?= is_array($cell) ? implode('<br>', $cell) : $cell ?>
                </td>
            <?php endforeach; ?>
        </tr>
    <?php endforeach; ?>
</table>

輸出:

    <table>
    <tbody>
        <tr>
            <td>11.12</td>
            <td>22.775</td>
            <td>33.895</td>
            <td>22.12<br>12.23<br>23.895</td>
        </tr>
        <tr>
            <td>1.12</td>
            <td>33.775</td>
            <td>44.895</td>
            <td>23.3<br>0<br>997.3</td>
        </tr>
    </tbody>
</table>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM