我正在尝试使用PHP创建一个表。
出于某种原因,我无法显示密钥。知道为什么吗?
这是表格。
这是我尝试过的代码:
String[] array = {"Henry", "Henry", "Henry", "Maxwell", "Maxwell"};
HashMap<String, Integer> duplicates = new HashMap<String, Integer>();
for (String s : array) {
Integer i = duplicates.get(s);
duplicates.put(s, i == null ? 1 : (i+1));
}
有什么想法吗?
答案 0 :(得分:5)
试试这个
#include <stdio.h>
int main(void)
{
int Val_MAX = 0;
printf("Enter the value of Val_MAX\n");
scanf("%d", &Val_MAX);
if(Val_MAX)
printf("The value is %d",VALUE_MAX);
return 0;
}
简要说明:
正如您在图像中所示,您需要定义预定义的标题,这些标题可以使用<table>
<tr>
<th>User #</th>
<th>First Name</th>
<th>Last Name</th>
<th>Full Name</th>
<th>Full Name in UpperCase</th>
</tr>
<?php
$users = array(
array('first_name' => 'Michael', 'last_name' => 'Choi'),
array('first_name' => 'John', 'last_name' => 'Supsupin'),
array('first_name' => 'Mark', 'last_name' => 'Guillen'),
array('first_name' => 'KB', 'last_name' => 'Tonel')
);
foreach ($users as $key => $user) {
echo "<tr>";
echo "<td>" , $key + 1 , "</td>";
echo "<td>" . $user['first_name'] . "</td>";
echo "<td>" . $user['last_name'] . "</td>";
echo "<td>" . $user['first_name'] . " " . $user['last_name'] . "</td>";
echo "<td>" . strtoupper($user['first_name']) . " " . strtoupper($user['last_name']) . "</td>";
echo "<td></td>";
echo "</tr>";
}
?>
</table>
以及从<th></th>
数组中获取的其余值来完成,这些数据可以放在循环中。< / p>
注意:在这里你需要使用单循环而不是嵌套循环,如例子所示
答案 1 :(得分:0)
您应该使用<tr>
和<td>
。
<table border="1">
<?php
$users = array(
array('first_name' => 'Michael', 'last_name' => 'Choi'),
array('first_name' => 'John', 'last_name' => 'Supsupin'),
array('first_name' => 'Mark', 'last_name' => 'Guillen'),
array('first_name' => 'KB', 'last_name' => 'Tonel')
);
$array_number = count($users)-1;
for($i=0; $i<=$array_number; $i++){
?>
<tr> <td><?php echo $users[$i]['first_name']; ?></td><td><?php echo $users[$i]['last_name']; ?></td> </tr>
<?php }
?>
</table>
答案 2 :(得分:0)
问题是你在数组上循环两次,一次是foreach
,一次是for
。但是你只需要一个循环。选择一个。
另外,养成在回显变量内容时始终使用htmlspecialchars
的习惯。在这种情况下它不重要,但有时,你不知道变量在哪里!
另外,请参阅Amol的答案。
答案 3 :(得分:0)
<table> <?php
$users = array( array('first_name' => 'Michael', 'last_name' => 'Choi'), array('first_name' => 'John', 'last_name' => 'Supsupin'), array('first_name' => 'Mark', 'last_name' => 'Guillen'), array('first_name' => 'KB', 'last_name' => 'Tonel') );
$i = 1;
foreach($users as $key => $user) {
echo "<tr>";
echo "<td>" . $i . "</td>";
echo "<td>" . $user['first_name'] . "</td>";
echo "<td>" . $user['last_name'] . "</td>";
echo "</tr>"; $i++;
}
?>
</table>
希望有所帮助
答案 4 :(得分:0)
<table>
<tr>
<th>User #</th>
<th>First Name</th>
<th>Last Name</th>
<th>Full Name</th>
<th>Full Name in UpperCase</th>
</tr>
<?php
$users = array(
array('first_name' => 'Michael', 'last_name' => 'Choi'),
array('first_name' => 'John', 'last_name' => 'Supsupin'),
array('first_name' => 'Mark', 'last_name' => 'Guillen'),
array('first_name' => 'KB', 'last_name' => 'Tonel')
);
foreach ($users as $key => $user) {
echo "<tr>";
echo "<td>" , $key + 1 , "</td>";
echo "<td>" . $user['first_name'] . "</td>";
echo "<td>" . $user['last_name'] . "</td>";
echo "<td>" . $user['first_name'] . " " . $user['last_name'] . "</td>";
echo "<td>" . strtoupper($user['first_name']) . " " . strtoupper($user['last_name']) . "</td>";
echo "<td></td>";
echo "</tr>";
}
?>
`