要将PHP中的数据传递给HTML表格,可以使用以下步骤:
以下是一个示例代码,演示如何传递数据给HTML表格:
在PHP文件中(例如,data.php):
<?php
// 存储要传递给表格的数据
$data = array(
array('John', 'Doe', 'john@example.com'),
array('Jane', 'Smith', 'jane@example.com'),
array('Bob', 'Johnson', 'bob@example.com')
);
?>
在HTML文件中(例如,table.html):
<!DOCTYPE html>
<html>
<head>
<title>Table Example</title>
</head>
<body>
<table>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<?php foreach($data as $row): ?>
<tr>
<td><?php echo $row[0]; ?></td>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>
在上述示例中,PHP文件中的$data数组包含要传递给表格的数据。在HTML文件中,使用foreach循环遍历数组中的每一行,并将数据插入到表格的每个单元格中。
当你访问table.html文件时,将会显示一个包含PHP文件中$data数组数据的表格。
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站