PHP tags are used to organize tabular data, including: column labels (
Usage of tags in PHP: A closer look at columns and rows
In PHP, tags are used to combine and organize HTML Structural elements for data in tables. They are typically used to define columns and rows in tables.
Column labels ( Row label ( Merge cells You can use the colspan and rowspan attributes to merge cells. Practical case: display employee data The following PHP script demonstrates how to use tags to create an employee data table: Run this script An HTML table will be generated containing data for employee ID, name, and age. The above is the detailed content of Tag Usage in PHP: Understanding Columns and Rows. For more information, please follow other related articles on the PHP Chinese website!)
labels define header columns. It usually contains the title or description of the column. echo "<th>姓名</th>";
echo "<th>年龄</th>";
) label defines a row. It contains the cells in the table. echo "<tr>";
echo "<td>约翰</td>";
echo "<td>30</td>";
echo "</tr>";
echo "<table border='1'>";
echo "<tr>";
echo "<th colspan='2'>个人信息</th>";
echo "</tr>";
echo "<tr>";
echo "<td rowspan='2'>姓名</td>";
echo "<td>约翰</td>";
echo "</tr>";
echo "<tr>";
echo "<td>30</td>";
echo "</tr>";
echo "</table>";
<?php
$employees = array(
array('id' => 1, 'name' => '约翰', 'age' => 30),
array('id' => 2, 'name' => '玛丽', 'age' => 25)
);
?>
<!DOCTYPE html>
<html>
<head>
<title>员工数据</title>
</head>
<body>
<table>
<tr>
<th>ID</th>
<th>姓名</th>
<th>年龄</th>
</tr>
<?php foreach ($employees as $employee) : ?>
<tr>
<td><?php echo $employee['id']; ?></td>
<td><?php echo $employee['name']; ?></td>
<td><?php echo $employee['age']; ?></td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>