第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

PHP 解析多維數(shù)組

PHP 解析多維數(shù)組

PHP
守候你守候我 2023-11-03 16:54:05
我有以下 PHP 數(shù)組輸出:Array(    [ON] => Array        (            [0] => Array                (                    [Name] => James Smith                    [Claim/Policy Number] => 787878                    [Province] => ON                    [Internal code] => 6987                    [Total (including tax)] => $ 5,299.97                )            [1] => Array                (                    [Name] => John Smith                    [Claim/Policy Number] => 9999999                    [Province] => ON                    [Internal code] => 1234                    [Total (including tax)] => $ 3,136.32                )            [2] => Array                (                    [Name] => John Smith1                    [Claim/Policy Number] => 909090                    [Province] => ON                    [Internal code] => 2873                    [Total (including tax)] => $ 1,996.81                )        )    [AB] => Array        (            [4] => Array                (                    [Name] => John Smith                    [Claim/Policy Number] => 545454                    [Province] => AB                    [Internal code] => 8909                    [Total (including tax)] => $ 3,720.40                )            [7] => Array                (                    [Name] => John Smith1                    [Claim/Policy Number] => 223343                    [Province] => AB                    [Internal code] => 1113                    [Total (including tax)] => $ 3,567.89                )        ))我正在嘗試找到將其格式化為下表結(jié)構(gòu)的最佳方法:<h2>AB</h2><table>    <tr>        <td>        Name        </td>        <td>        Claim/Policy Number        </td>        <td>        Internal Code        </td>        <td>        Total (including tax)        </td>    </tr>我需要循環(huán)足夠靈活,以便為每個(gè)子數(shù)組編寫(xiě)一個(gè)帶有標(biāo)題的新表。循環(huán)此數(shù)組以輸出數(shù)組中每個(gè)子數(shù)組的新表和標(biāo)頭的最佳方法是什么?
查看完整描述

1 回答

?
HUH函數(shù)

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超4個(gè)贊

您只需要在 foreach 中包含一個(gè) foreach 即可。


工作示例:


<?php

$tables = [

    'ON' => [

        '0' => [

            'Name' => 'James Smith',

            'Claim/Policy Number' => '787878',

            'Province' => 'ON',

            'Internal code' => '6987',

            'Total (including tax)' => '$ 5,299.97',

        ],

        '1' => [

            'Name' => 'John Smith',

            'Claim/Policy Number' => '9999999',

            'Province' => 'ON',

            'Internal code' => '1234',

            'Total (including tax)' => '$ 3,136.32',

        ],

        '2' => [

            'Name' => 'John Smith1',

            'Claim/Policy Number' => '909090',

            'Province' => 'ON',

            'Internal code' => '2873',

            'Total (including tax)' => '$ 1,996.81',

        ],

    ],

    'AB' => [

        '4' => [

            'Name' => 'John Smith',

            'Claim/Policy Number' => '545454',

            'Province' => 'AB',

            'Internal code' => '8909',

            'Total (including tax)' => '$ 3,720.40',

        ],

        '7' => [

            'Name' => 'John Smith1',

            'Claim/Policy Number' => '223343',

            'Province' => 'AB',

            'Internal code' => '1113',

            'Total (including tax)' => '$ 3,567.89',

        ],

    ]

];

?>


<!DOCTYPE html>

<html>


<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

</head>


<body>

    <?php foreach($tables as $name => $table): ?>

    <h2><?= $name ?></h2>

    <table>

        <tr>

            <th>Name</th>

            <th>Claim/Policy Number</th>

            <th>Internal Code</th>

            <th>Total (including tax)</th>

        </tr>

        <?php foreach($table as $row): ?>

        <tr>

            <td><?= $row['Name'] ?></td>

            <td><?= $row['Claim/Policy Number'] ?></td>

            <td><?= $row['Internal code'] ?></td>

            <td><?= $row['Total (including tax)'] ?></td>

        </tr>

        <?php endforeach; ?>

    </table>

    <?php endforeach; ?>

</body>

</html>



查看完整回答
反對(duì) 回復(fù) 2023-11-03
  • 1 回答
  • 0 關(guān)注
  • 197 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)