php - 在php中将数组转换为html表
问题描述
我有一个由 API 生成的数组,我使用带有 php 5.6 的 cpanel 托管。
我尝试了很多组合但没有用
该数组由 emag 市场 API 生成。
代码看起来像
Array
(
[isError] =>
[messages] => Array
(
)
[results] => Array
(
[0] => Array
(
[vendor_name] => WISE COMPUTER SRLD
[id] => 2003677675
[parent_id] =>
[date] => 2017-05-21 10:55:18
[payment_mode] => RAMBURS
[payment_mode_id] => 1
[delivery_mode] => CURIER RO
[observation] =>
[status] => 4
[payment_status] => 0
[customer] => Array
(
[id] => 994041
[mkt_id] => 994041
[name] => Cristina Manuela Dancas
[company] => Cristina Manuela Dancas
[gender] =>
[phone_1] => 0743073616
[phone_2] =>
[phone_3] =>
[registration_number] =>
[code] =>
[email] =>
[billing_name] =>
[billing_phone] =>
[billing_country] => RO
[billing_suburb] => Bucuresti
[billing_city] => Sectorul 1
[billing_locality_id] => 2
[billing_street] => Str. Aviator Sanatescu nr. 57, parter, Ap1
[billing_postal_code] =>
[shipping_country] => RO
[shipping_suburb] => Bucuresti
[shipping_city] => Sectorul 1
[shipping_locality_id] => 2
[shipping_postal_code] =>
[shipping_contact] => Cristina Manuela Dancas
[shipping_phone] => 0743073616
[created] => 2017-05-21 10:55:19
[modified] => 2017-05-21 10:56:21
[bank] =>
[iban] =>
[legal_entity] => 0
[fax] =>
[is_vat_payer] => 1
[liable_person] =>
[shipping_street] => Str. Aviator Sanatescu nr. 57, parter, Ap1
)
我在 HTML 表中使用 php 转换什么。
需要一些帮助。如果您需要更多信息,请留言。
解决方案
这是我从 PHP 数组创建 HTML 表格的快速解决方案。本质是,二维数组变成了一个有意义的表。您的数组似乎更复杂,因此转换为有用的表可能需要更多的努力。
$data = array( array("ID","Firstname","Lastname","Phone"),
array("1","John","Jenkins","+91375953"),
array("2","Eduard","Kenny","+7244277"),
array("3","Anita","Beaumont","+427427427"),
array("4","Wanda","Wade","+274274247"),
array("4","Sarah","Colon","+835835"),
);
echo '<table border="1">';
foreach($data as $row) {
echo '<tr>';
foreach($row as $cell) {
echo '<td>'.$cell.'</td>';
}
echo '</tr>';
}
echo '</table>';
推荐阅读
- r - 如何在 r 中的同一进程中在预先建立的区域内创建缓冲区和剪辑?
- wordpress-theming - 如何使用 wp_insert_post 创建包含 Elementor 内容的页面?
- csv - 通过 CSV 文件的热图
- html - 如何更改离子图标的标题?
- javascript - 如何将实时数据存储在 Javascript 数组中?
- javascript - 空白局部变量声明 - JS
- design-patterns - 游戏中装备或取消装备的设计模式
- wordpress - 如何使用 NGNIX 指令将所有请求重定向到目录中的文件,但对特定子目录中文件的请求除外?
- html - 数据列表元素,可以自动填充多个输入吗?
- css - GetComputedStyle 节点不工作 - 未定义