我想在首页打印一个数组作为表格,但我不想显示姓氏。如何在PHP中编写代码来执行此操作?
?php
// Array representing a possible record set returned from a database
$records = array(
array(
'id' => 2135,
'first_name' => 'John',
'last_name' => 'Doe',
),
array(
'id' => 3245,
'first_name' => 'Sally',
'last_name' => 'Smith',
),
array(
'id' => 5342,
'first_name' => 'Jane',
'last_name' => 'Jones',
),
array(
'id' => 5623,
'first_name' => 'Peter',
'last_name' => 'Doe',
)
);
请帮忙
答案 0 :(得分:1)
试试这个
<table>
<?php
foreach ($records as $key => $value) {
echo "<tr>";
echo "<td>".$value['id']."</td>";
echo "<td>".$value['first_name']."</td>";
echo "</tr>";
}
?>
</table>
这将以表格格式显示 id 和 first_name 。
答案 1 :(得分:0)
<table>
<?php
foreach ($records as $value) {
echo "<tr>";
echo "<td>".$value['id']."</td>";
echo "<td>".$value['first_name']."</td>";
echo "</tr>";
}
?>
</table>