php - codeIgniter View 文件中表格格式的特定方式的数组表示?

标签 php html codeigniter html-table dompdf

我有一个格式如下的数组。这个数组有大约 100 个相同格式的元素。我想使用 DOMPDF 以特定格式的表格表示整个数组使用 codeIgniter 的库。

result = Array(
              [0] => Array (
                     ['brand'] => x,
                     ['product'] =>p1,
                     ['language']=>English,
                    );
              [1] => Array (
                     ['brand'] => x,
                     ['product'] =>p2,
                     ['language']=>English,
                    );
              );

我喜欢用 <table> 以下面的格式表示它们html 中的标签.

  Brand          x             y
  Product        p1            p2
  Language       English       English

我正在寻找想法。我有那些数组元素不超过 100 个。我想循环它们。

因此,根据下面的请求,我将发布我的代码。

<?php foreach($result as $res)

 {
  <table>
    <tr>
        <td>Brand</td>
        <td><?php echo $res['brand'] ?></td>
    </tr>
    <tr>
        <td>Product</td>
        <td><?php echo $res['product'] ?></td>
    </tr>
    <tr>
        <td>Language/td>
        <td><?php echo $res['language'] ?></td>
    </tr>
  </table>
}

这将为您提供这样一种产品的输出。 品牌 x
产品p1
语言英文

我如何为其他产品循环以获得我想要的上述输出?

注意:不是每个数组元素只有3个字段。我有 30 多个字段。您可能认为我这样做只是因为 PDF 页面中的可打印区域。

最佳答案

使用 foreach用于从结果数组中获取每个数组。并使用 multiple array (row[ ][ ])key .你可以打印<tr><td>都在echo .

关于php - codeIgniter View 文件中表格格式的特定方式的数组表示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13967839/

相关文章:

php - 如何在分页库codeigniter中编写Segment

php - 用于分页的 Codeigniter count_all

php - MySql 事务

PHP:如何在 Paypal IPN系统中集成userid?

html - 垂直居中一些图像

php - 如何以自动递增且不重复的方式发布ID

html - 与 Flexbox 相同的宽度

javascript - 在输入组中引导 5 个 float 标签

php - 如何使用其他变量在路由中传递表单数据?

php - 设置 Apache 虚拟主机 (CentOs)