数组到表,键名为垂直标题

时间:2015-10-14 14:30:24

标签: php

我有一个如下所示的数组$ a:

git clone https://some.git.server/project.git
cd project/subdir
git init
git remote add -f origin https://some.git.server/another.project.git
echo Source/Base > .git\info\parse-checkout
echo Source/Core > .git\info\parse-checkout
git pull origin master 
...

我想将输出操作到垂直表中,如下所示:

Array
(
    [0] => Array
        (
            [Date] => 2015-10-11
            [Time] => 18:45:00
            [Protocol] => TLSv1.0
        )

    [1] => Array
        (
            [Date] => 2015-10-11
            [Time] => 23:43:24
            [Protocol] => TLSv1.2
        )

    [2] => Array
        (
            [Date] => 2015-10-11
            [Time] => 23:45:18
            [Protocol] => TLSv1.1
        )

)

1 个答案:

答案 0 :(得分:1)

这就是我要做的事情:

    // $arr is your array.
    $final = array();
    foreach ($arr as $chunk) {
        $final['Date'][] = $chunk['Date'];
        $final['Time'][] = $chunk['Time'];
        $final['Protocol'][] = $chunk['Protocol'];
    }
    ?>
    <table>
        <?php foreach ($final as $k => $chunk) { ?>
            <tr>
                <td><?= $k ?></td>
                <?php foreach ($chunk as $row) { ?>
                    <td><?= $row ?></td>
                <?php } ?>
            </tr>
        <?php } ?>
    </table>